We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
package main.java.com.poogle.PG.Q42576; import java.util.Arrays; public class Solution { public String solution(String[] participant, String[] completion) { Arrays.sort(participant); Arrays.sort(completion); int playerIndex = 0; for (playerIndex = 0; playerIndex < completion.length; playerIndex++) { if (!participant[playerIndex].equals(completion[playerIndex])) { return participant[playerIndex]; } } return participant[playerIndex]; } }
import java.util.Map; import java.util.HashMap; class Solution { public String solution(String[] participant, String[] completion) { String answer = ""; Map<String, Integer> map = new HashMap<>(); for (String person : participant) { map.put(person, map.getOrDefault(person, 0) + 1); } for (String player : completion) { map.put(player, map.get(player) - 1); } for (String key : map.keySet()) { if (map.get(key) != 0) { answer = key; break; } } return answer; } }
import java.util.Map; import java.util.HashMap; import java.util.Iterator; class Solution { public String solution(String[] participant, String[] completion) { String answer = ""; Map<String, Integer> map = new HashMap<>(); for (String person : participant) { map.put(person, map.getOrDefault(person, 0) + 1); } for (String player : completion) { map.put(player, map.get(player) - 1); } Iterator<Map.Entry<String, Integer>> iterator = map.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, Integer> entry = iterator.next(); if (entry.getValue() != 0) { answer = entry.getKey(); break; } } return answer; } }
The text was updated successfully, but these errors were encountered:
1565147
suhyunsim
No branches or pull requests
문제
핵심 아이디어
어려운 점, 실수
풀이
배열로 풀이
Map Key로 풀이
EntrySet으로 풀이
The text was updated successfully, but these errors were encountered: