내 답안
import java.util.*;
class Solution {
public List<Integer> solution(int n, int k) {
List<Integer> answer = new ArrayList<>();
for (int i = 1; k * i <= n; i++) {
answer.add(k*i);
}
return answer;
}
}
Java
복사
다른사람 풀이
class Solution {
public int[] solution(int n, int k) {
int count = n / k;
int[] answer = new int[count];
for (int i = 1; i <= count; i++) {
answer[i - 1] = k * i;
}
return answer;
}
}
Java
복사
import java.util.stream.IntStream;
class Solution {
public int[] solution(int n, int k) {
return IntStream.rangeClosed(1, n).filter(i -> i % k == 0).toArray();
}
}
Java
복사
class Solution {
public String solution(String my_string, int s, int e) {
char[] arr = my_string.toCharArray();
while (s < e) {
char temp = arr[s];
arr[s++] = arr[e];
arr[e--] = temp;
}
return new String(arr);
}
}
Java
복사