내 답안
import java.util.HashMap;
import java.util.Map;
class Solution {
public int solution(String[] strArr) {
HashMap<Integer, Integer> map = new HashMap<>();
for (String str : strArr) {
int length = str.length();
map.put(length, map.getOrDefault(length, 0) + 1);
}
int maxCount = 0;
for (int count : map.values()) {
maxCount = Math.max(maxCount, count);
}
return maxCount;
}
}
Java
복사
다른사람 풀이
class Solution {
public int solution(String[] strArr) {
int answer = 0;
int[] lengArr = new int[31];
for(int i=0; i<strArr.length; i++) {
lengArr[strArr[i].length()]++;
}
for(int i=0; i<=30; i++) {
answer = Math.max(answer, lengArr[i]);
}
return answer;
}
}
Java
복사
class Solution {
public int solution(String[] strArr) {
int answer = 0;
int[] count = new int[30 + 1];
for (int i = 0; i < strArr.length; i++) {
count[strArr[i].length()]++;
}
for (int x : count) {
answer=Math.max(answer,x);
}
return answer;
}
}
Java
복사