[Programmers] 완주하지 못한 선수 #2
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[완주하지 못한 선수]
문제 이해
참여한선수 participant와 완주한 선수completion을 비교해서 완주하지 못한 선수의 이름을 return해야된다. 즉, participant와 completion를 비교해서 completion에 없는배열값을 return
해결방법
participant.sort();completion.sort();예)
참여명단: [6,2,4,5].sort() → [2,4,5,6]
완주명단: [6,4,5].sort() → [4,5,6]
for문 안에서 [2,4,5,6] 과 [4,5,6]을 비교한 후 다른 숫자를 반환
→ 2와4를 비교한 후 다르니까 2를 반환
[포켓몬]
문제이해
배열이 있고 포켓몬을 배열개수의 반을 가지고 데리고 갈 수 있다. 근데 중복된 종류의 포켓몬이 있다면 한마리만 데리고 갈 수 있음.
예) [3,3,3,2,2,2] → 6 / 2 = 3 세마리를 데리고 갈 수 있지만 총 두종류 밖에 없으니까 두마리만 데리고 갈 수 있음
해결방법
const set = new Set([1,2,3,1,1]);nums.length / 2;실패코드