728x90

https://school.programmers.co.kr/learn/courses/30/lessons/181838

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

문제)정수 배열 date1과 date2가 주어집니다. 두 배열은 각각 날짜를 나타내며 [year, month, day] 꼴로 주어집니다. 각 배열에서 year는 연도를, month는 월을, day는 날짜를 나타냅니다.

만약 date1이 date2보다 앞서는 날짜라면 1을, 아니면 0을 return 하는 solution 함수를 완성해 주세요.

 

 

 

 

 

 

 

 

풀이)

class Solution {
    public int solution(int[] date1, int[] date2) {
        int answer = 0;
        
        if(date2[0]-date1[0]>0){
            answer = 1;
        }

        if(date2[0]-date1[0]==0){
            if(date2[1]-date1[1]>0){
                answer = 1;
            }
        }

        if(date2[0]-date1[0]==0){
            if(date2[1]-date1[1]==0){
                if(date2[2]-date1[2]>0){
                    answer = 1;
                }
            }
        }
        return answer;
    }
}
728x90