[프로그래머스 / Java] 나이 출력

Dreamer·2023년 12월 8일
0
post-thumbnail

문제

입문 문제5

나의 풀이

class Solution {
    public int solution(int age) {
        int answer = 0;
        answer = 2022 - age + 1;
        return answer;
    }
}

생각

매우 직관적으로 풀어서 민망하다.

다른 풀이

import java.time.*;
class Solution {
    public int solution(int age) {
        LocalDate today = LocalDate.now();
        return today.getYear() - age + 1;
    }
}

도대체 이런 생각은 어떻게 하는걸까? 대단하다.

profile
Moving forward based on records

0개의 댓글