사용언어 : Java
문제

풀이
class Solution {
public int solution(int[] num_list) {
int answer = num_list[0];
int length = num_list.length;
for(int i = 1 ; i < length; i++)
{
if(length > 10)
{
answer += num_list[i];
}
else
{
answer *= num_list[i];
}
}
return answer;
}
}
초기값을 0으로 지정했을 때 모든 원소의 곱 처리를 진행할 떄 0 x … 로 시작하기에 초기값만 설정을 잘해두면 문제없이 잘 동작한다
Share article