코딩테스트 풀이/JAVA
[프로그래머스/Lv.0] 날짜 비교하기
무지맘
2023. 5. 1. 19:57
1. Input, Output, Example
두 배열은 각각 날짜를 나타내며 [year, month, day] 꼴로 주어진다. 각 배열에서 year는 연도를, month는 월을, day는 날짜를 나타낸다.
- 만약 date1이 date2보다 앞서는 날짜라면 1을, 아니면 0을 반환
2. Constraint
1) date1의 길이 = date2의 길이 = 3
2) 0 ≤ year ≤ 10,000
3) 1 ≤ month ≤ 12
4) day는 month에 따라 가능한 날짜로 주어진다.
3. Code
1) 첫 코드(2023/05/01)
class Solution {
public int solution(int[] date1, int[] date2) {
int answer = 0;
if(date1[0]<date2[0])
answer = 1;
else if(date1[0]==date2[0]){
if(date1[1]<date2[1])
answer = 1;
else if(date1[1]==date2[1] && date1[2]<date2[2])
answer = 1;
}
return answer;
}
}