import java.util.Scanner;
public class Main1065 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int N = s.nextInt();
System.out.println(hansu(N));
}
public static int hansu(int N) {
int count = 0;
for (int i = 1; i <= N; i++) {
if (i < 100) {
count++;
} else {
int n1 = (i / 100);
int n2 = (i % 100 / 10);
int n3 = (i % 100 % 10);
if (n1 - n2 == n2 - n3) {
count++;
}
}
}
return count;
}
}
개선점 : 아래 함수는 최소한의 시간으로 끝낼 수 있는 방법이라고 생각된다.
Main함수에서 입력을 받을 때 Scanner가 아닌 BufferedReader로 받으면 시간이 더욱 절약된다.
최대한 Scanner을 사용안하는쪽을 지향해야 할것 같다.
'휴지통 > 알고리즘 & 자료구조' 카테고리의 다른 글
백준 11654 (0) | 2021.07.10 |
---|---|
Greedy_Algorithm (탐욕 알고리즘) (0) | 2021.07.10 |
백준 4673 (0) | 2021.07.09 |
백준 15596 (0) | 2021.07.09 |
깊이 우선 탐색 (DFS) (0) | 2021.07.09 |