내 답안
class Solution {
public int[] solution(int[] arr) {
int len = arr.length;
int tmp = 1;
while (tmp < len) {
tmp *= 2;
}
int[] answer = new int[tmp];
for (int i = 0; i < arr.length; i++) {
answer[i] = arr[i];
}
return answer;
}
}
Java
복사
다른사람 풀이
import java.util.*;
class Solution {
public int[] solution(int[] arr) {
int length = 1;
while (length < arr.length) {
length *= 2;
}
return Arrays.copyOf(arr, length);
}
}
Java
복사
class Solution {
public int[] solution(int[] arr) {
int len = arr.length;
int pow = 0;
while(len > Math.pow(2, pow)) {
pow++;
}
int[] answer = new int[(int)Math.pow(2, pow)];
for(int i = 0; i < len; i++) {
answer[i] = arr[i];
}
return answer;
}
}
Java
복사