Skip to content

Commit

Permalink
Merge pull request #148 from algo-malgo/algorithm/#148
Browse files Browse the repository at this point in the history
롤케이크 자르기
  • Loading branch information
NamJwong authored Apr 12, 2023
2 parents 6ab5c0f + e119681 commit e2633a3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions PG/롤케이크 자르기.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function solution(topping) {
let answer = 0;

const 철수 = new Map();
const 동생 = new Map();

topping.forEach((t, index) => {
철수.set(t, 철수.get(t) + 1 || 1);
});

topping.forEach((t) => {
동생.set(t, 동생.get(t) + 1 || 1);
철수.set(t, 철수.get(t) - 1);

if (철수.get(t) < 1) {
철수.delete(t);
}

if (동생.size === 철수.size) {
answer++;
}
});

return answer;
}

0 comments on commit e2633a3

Please sign in to comment.