Skip to content

Commit

Permalink
정답
Browse files Browse the repository at this point in the history
  • Loading branch information
NamJwong committed Apr 12, 2023
1 parent 6ab5c0f commit e119681
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 e119681

Please sign in to comment.