첫 번째 풀이한 내용 JAVA
class Solution {
public int solution(int[] common) {
int answer = 0;
for (int i =1; i<common.length; i++ ){
if( common[i]-1 == common[i-1]){
if( i+1 == common.length){
answer = common[common.length-1] + 1;
return answer;
}
}
else{
if( i+1 == common.length){
answer = common[common.length-1] * 2;
return answer;
}
}
}
return answer;
}
}
두 번째 풀이한 내용 JAVA
class Solution {
public int solution(int[] common) {
int answer = 0;
if ( (common[1] - common[0] )== (common[2] - common[1])){
answer = common[common.length-1] + (common[1] -common[0]);
} else{
answer = common[common.length-1] * (common[1] / common[0]);
}
return answer;
}
}
첫 번째 풀이한 내용 Kotlin
class Solution {
fun solution(common: IntArray): Int {
var answer: Int = 0
if( (common[1] - common[0]) == (common[2]- common[1])){
answer = common[common.size-1] + (common[1] - common[0])
} else{
answer = common[common.size-1] * (common[1] / common[0])
}
return answer
}
}