📝 문제
백준 - 1065번 : 한수 (Silver IV)
📝 답안
📌 작성 코드
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int result = 0;
for (int i = 1; i <= n; i++) {
result += check(i) ? 1 : 0;
}
System.out.println(result);
}
public static boolean check(int num) {
ArrayList<Integer> list = new ArrayList<>();
while (num > 0) {
int temp = num % 10;
list.add(temp);
num /= 10;
}
boolean result = true;
for (int i = 1; i < list.size()-1; i++) {
int a = list.get(i-1);
int b = list.get(i);
int c = list.get(i+1);
if (a - b != b - c) {
result = false;
break;
}
}
return result;
}
}
📌 결과