Q.정수가 담긴 리스트 num_list가 주어집니다. num_list의 홀수만 순서대로 이어 붙인 수와 짝수만 순서대로 이어 붙인 수의 합을 return하도록 solution 함수를 완성해주세요.
이어 붙이는 수의 합이니까 String으로 빈 값을 받아와야한다.
Integer.parseInt로 int로 변환하면 된다.
class Solution {
public int solution(int[] num_list) {
int answer = 0;
String a = "";
String b = "";
for(int i = 0; i<num_list.length; i++){
if(num_list[i] % 2 == 0){
a += num_list[i]+"";
}else{
b += num_list[i]+"";
}
}
return answer = Integer.parseInt(a)+Integer.parseInt(b);
}
}