Algorithm88 [Lv. 1] 개인정보 수집 유효기간 주어진 약관들 중에서 개인정보가 만료된 약관의 번호를 구하면 되는 문제이다. 1. 누적된 총 날짜를 가져오는 함수 getTotalDate를 생성한다 2. 비교하기 쉽도록 주어진 약관들을 map을 생성해 넣어준다 3. 주어진 약관들을 비교하며 파기해야하는 약관인지 확인한다 class Solution { public int[] solution(String today, String[] terms, String[] privacies) { List answer = new ArrayList(); Map period = new HashMap(); int date = getTotalDate(today); for(String t: terms){ String[] term = t.split(" "); period.put(t.. Algorithm/프로그래머스 2023. 7. 30. [Lv. 1] 햄버거 만들기 문제가 엄청 긴데 그냥 쉽게 말해서 주어진 배열에서 1, 2, 3, 1이 순서대로 있으면 이게 바로 햄버거 한 개! 만들어지면 없애주고 또 만들 수 있는 햄버거가 있나 확인하면 된다! 1. 사용할 자료구조 선언 2. 자료구조에 ingredient 배열에 있는 요소 추가 3. 조건 확인 - 햄버거 1개를 만드려면 최소 4개의 재료가 필요하므로 사이즈는 언제나 3보다 커야함 - 1, 2, 3, 1 이 순서대로 있어야 함 4. 조건을 만족하면 answer를 1 증가 시키고 사용한 재료를 제거함 그래서 처음엔 링크드리스트로 구현을 해봤는데 class Solutions{ public int solution(int[] ingredient) { int answer = 0; LinkedList linkedList = .. Algorithm/프로그래머스 2023. 7. 29. [Level 1] 숫자 문자열과 영단어 class Solution { public int solution(String s) { String[] arr = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; for(int i=0;i Algorithm/프로그래머스 2023. 7. 23. [고득점kit/완전탐색] 피로도 class Solution { static boolean[] visited; static int max = 0; void explore(int piro, int[][] dungeons, int cnt) { // 모든 케이스 순회 for (int i = 0; i < dungeons.length; i++) { int a = dungeons[i][0]; int b = dungeons[i][1]; // 기존에 방문 확인, 최소 피로도 확인 if (visited[i] || piro < a) { continue; } // 방문 visited[i] = true; explore(piro - b, dungeons, cnt + 1); // 다른 케이스를 위해 방문 취소 visited[i] = false; } max = M.. Algorithm/프로그래머스 2023. 7. 16. [고득점kit/완전탐색] 모의고사 사실 문제를 똑바로 안읽고 그냥 냅다 풀다가 어라라? 1번/2번/3번이 주어진게 없는데?!해버린 문제이다. 새삼 다시 한 번 문제를 똑바로 읽어야겠다고 생각하게 되었다지요.. class Solution { public int[] solution(int[] answers) { int[] person1 = {1, 2, 3, 4, 5}; int[] person2 = {2, 1, 2, 3, 2, 4, 2, 5}; int[] person3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; int s1 = 0; int s2 = 0; int s3 = 0; for(int i = 0; i < answers.length; i++){ if(person1[i % person1.length] == answers[i].. Algorithm/프로그래머스 2023. 7. 6. [고득점kit/깊이/너비 우선 탐색] 타겟 넘버 비교적 쉽게 풀 수 있었다! 사실 처음엔 주어진 수를 다 더해서 sum - target을 한 다음에 나온 값을 만들어 보는 방식으로 해볼까 했는데 당연히 쓸데 없는 단계가 한번 더 추가 되면 비효율적이죠? class Solution { int answer = 0; public int solution(int[] numbers, int target) { //재귀 호출 dfs(numbers, target, 0, 0); return answer; } public void dfs(int[] numbers, int target, int depth, int sum){ if(depth == numbers.length){ if(sum == target) answer++; }else{ dfs(numbers, target,.. Algorithm/프로그래머스 2023. 6. 22. [고득점kit/완전탐색] 모음 사전 import java.util.*; class Solution { static String[] arr; static List list; public int solution(String word) { int answer = 0; list = new ArrayList(); arr = new String[]{"A", "E", "I", "O", "U"}; recursion(word, "", 0); for (int i = 0; i < list.size(); i++) { if(list.get(i).equals(word)) { answer = i; break; } } return answer; } static void recursion(String word, String str, int depth) { list.ad.. Algorithm/프로그래머스 2023. 6. 22. [고득점kit/완전탐색] 소수찾기 사실 처음엔 n 자리에 올 수 있는 수 / 올 수 없는 수 이렇게 나눠서 풀려다가 이게 효율이 더 떨어질 것 같다는 생각이 팍!들어서 그냥 구할 수 있는 모든 숫자의 조합을 구하고 소수 판별을 하기로 결정했다! import java.util.*; class Solution { HashSet numberSet = new HashSet(); public void recursive(String comb, String others){ //comb: 여태까지 조합된 숫자 //others: 사용하지 않은 숫자 //1. 현재 조합된 숫자를 set에 추가해줌 if(!comb.equals("")) //comb가 빈스트링이 아닐때 numberSet.add(Integer.valueOf(comb)); //2. 남은 숫자 중 .. Algorithm/프로그래머스 2023. 6. 21. [고득점kit/완전탐색]최소직사각형 import java.util.*; class Solution { public int solution(int[][] sizes) { int answer = 0; int a = 0; List list = new ArrayList(); //가로 List list2 = new ArrayList(); //세로 for(int i = 0; i list2.get(list.get(lis.. Algorithm/프로그래머스 2023. 6. 20. [고득점kit/정렬] k번째 수 class Solution { public int[] solution(int[] array, int[][] commands) { int[] answer = new int[commands.length]; for(int x = 0; x < 3; x ++){ List list = new ArrayList(); int i = commands[x][0]; int j = commands[x][1]; int k = commands[x][2]; for(i= i - 1 ; i < j ; i++){ list.add(array[i]); } Collections.sort(list); answer[x] = list.get(k - 1); } return answer; } } Algorithm/프로그래머스 2023. 5. 16. [Lv. 1] 같은 숫자는 싫어 class Solution { public int[] solution(int []arr) { int[] answer = {}; ArrayList list = new ArrayList(); int num = -1; for(int i = 0; i Algorithm/프로그래머스 2023. 5. 15. [Lv. 1] 부족한 금액 계산하기 class Solution { public long solution(int price, int money, int count) { long answer; long sum = 0; for(int i = 1; i 0) answer = sum - (long)money; else return 0; return answer; } } Algorithm/프로그래머스 2023. 5. 11. 이전 1 2 3 4 5 ··· 8 다음