내 답안
import java.util.*;
class Solution {
public int[] solution(String[] intStrs, int k, int s, int l) {
List<Integer> result = new ArrayList<>();
for (String str : intStrs) {
int i = Integer.parseInt(str.substring(s, s + l));
if (i > k) {
result.add(i);
}
}
return result.stream().mapToInt(i->i).toArray();
}
}
Java
복사
다른 사람 풀이법
import java.util.ArrayList;
class Solution {
public int[] solution(String[] intStrs, int k, int s, int l) {
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i < intStrs.length; i++) {
int tmp = Integer.parseInt(intStrs[i].substring(s, s + l));
if (tmp > k) {
list.add(tmp);
}
}
int[] answer = new int[list.size()];
for (int i = 0; i < answer.length; i++) {
answer[i] = list.get(i);
}
return answer;
}
}
Java
복사