Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

귤 고르기 #144

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

귤 고르기 #144

wants to merge 1 commit into from

Conversation

say-young516
Copy link
Contributor

🔗 Related Issues

🔍 문제

프로그래머스 - 귤 고르기

✅ 풀이 방법

추후 첨부

📜 최종 소스코드

function solution(k, tangerine) {
  let answer = 0;
  let mymap = new Map();

  for (let i = 0; i < tangerine.length; i++) {
    if (mymap.has(tangerine[i])) {
      mymap.set(tangerine[i], mymap.get(tangerine[i]) + 1);
    } else {
      mymap.set(tangerine[i], 1);
    }
  }
  const arr = [...mymap].sort((a, b) => b[1] - a[1]);
  for (let i = 0; i < arr.length; i++) {
    if (arr[i][1] >= k) {
      answer++;
      break;
    } else {
      answer++;
      k -= arr[i][1];
    }
  }
  return answer;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

귤 고르기
1 participant