내 답안
class Solution {
public int solution(int[] num_list) {
int answer = 0;
int result_sum = 0;
int result_mul = 1;
for(int i=0; i<num_list.length; i++){
result_sum += num_list[i];
result_mul *= num_list[i];
}
if(result_mul < (result_sum*result_sum) ){
answer = 1;
}else{
answer = 0;
}
return answer;
}
}
Java
복사
다른 사람 풀이법
import java.util.Arrays;
class Solution {
public int solution(int[] numList) {
return (Arrays.stream(numList).reduce((acc, i) -> acc * i).getAsInt() < Math.pow(Arrays.stream(numList).sum(), 2)) ? 1 : 0;
}
}
Java
복사
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Solution {
public int solution(int a, int b, int c) {
Set<Integer> numbers = Stream.of(a, b, c).collect(Collectors.toSet());
return (a + b + c) *
(numbers.size() < 3 ? a * a + b * b + c * c : 1) *
(numbers.size() < 2 ? a * a * a + b * b * b + c * c * c : 1);
}
}
Java
복사