본문 바로가기
알고리즘

[프로그래머스/150370] 개인정보 수집 유효기간

by 물고기고기 2023. 12. 4.

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

 

프로그래머스

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

programmers.co.kr

 

풀이

이러한 Date처리 문자열문제인데 Date타입을 잘 안다뤄봐서 전부 String으로 잘라서 풀었다.. 여러분은 나처럼 무식하게 풀지 마시길..

PS) 잘못된 풀이인줄 알았는데 찾아보니 사람들 대부분 이렇게 풀었다..

import java.util.*;

class Solution {
    public ArrayList solution(String today, String[] terms, String[] privacies) {
        
        int tYear = Integer.parseInt(today.substring(0,4));
        int tMonth = Integer.parseInt(today.substring(5,7));
        int tDay = Integer.parseInt(today.substring(8,10));
        
        Hashtable<String,Integer> privaciestable = new Hashtable<>();
        
        for(String p: terms){
            privaciestable.put(p.substring(0,1),Integer.parseInt(p.substring(2,p.length())));
        }
        
        ArrayList<Integer> overprivacy = new ArrayList<>();
        for(int i=0; i<privacies.length; i++){
            int pYear = Integer.parseInt(privacies[i].substring(0,4));
            int pMonth = Integer.parseInt(privacies[i].substring(5,7));
            int pDay = Integer.parseInt(privacies[i].substring(8,10));
            String pType = privacies[i].substring(11,12);
            
            int overDate = 0;
                
            int overY = (tYear - pYear) * 12 ;
            int overM = (tMonth - pMonth) ;
            
            overDate+= overY + overM;
            
            if(tDay - pDay < 0){
                overDate -= 1;
            }
            
            
            if(overDate >= privaciestable.get(pType)){
                int num = i+1;
                overprivacy.add(num);
            }
        }
        
        return overprivacy;
    }
}

 

일단은 정답

 


개인적으로 좋아보이는 풀이들

https://rovictory.tistory.com/172

 

(Java) 프로그래머스 - 개인정보 수집 유효기간

카카오 문제치고 쉬운 문제였다. 인풋 값도 적어서 시간 초과를 생각하지 않고 편한 마음으로 풀었다. Date와 SimpleDateFormat를 이용해서 계산하는 방법도 생각했지만 그냥 계산하는게 더 간단해 보

rovictory.tistory.com

https://iyk2h.tistory.com/338

 

[프로그래머스] 개인정보 수집 유효기간 자바(Java)

https://school.programmers.co.kr/learn/courses/30/lessons/150370 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞

iyk2h.tistory.com

 

댓글