코딩테스트-알고리즘/프로그래머스 20

[프로그래머스/Lv.2] 피로도

https://school.programmers.co.kr/learn/courses/30/lessons/87946 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { boolean[] visited; int answer = -1; public int solution(int k, int[][] dungeons) { visited = new boolean[dungeons.length]; adventure(k, dungeons, 0); return answer; } void adventure (int k, int[][] dungeons..

[프로그래머스/Lv.2] 전화번호 목록

https://school.programmers.co.kr/learn/courses/30/lessons/42577 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 최종 코드 import java.util.*; class Solution { public boolean solution(String[] phone_book) { boolean answer = true; int len = phone_book.length; Map map = new HashMap(); Arrays.sort(phone_book); for(int i = 0; i < len; i++) { ..

[프로그래머스/Lv.2] 타겟 넘버

https://school.programmers.co.kr/learn/courses/30/lessons/43165 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { int answer = 0; public int solution(int[] numbers, int target) { int sum = 0; int depth = 0; dfs(numbers, target, 0, 0); return answer; } void dfs(int[] numbers, int target, int depth, int sum) { if(depth =..

[프로그래머스/Lv.1] 완주하지 못한 선수

https://school.programmers.co.kr/learn/courses/30/lessons/42576 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.*; class Solution { public String solution(String[] participant, String[] completion) { String answer = ""; List list = new ArrayList(); for(int i=0; i

[프로그래머스/Lv.0] 정수를 나선형으로 배치하기

https://school.programmers.co.kr/learn/courses/30/lessons/181832 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { public int[][] solution(int n) { int[][] answer = new int[n][n]; int[][] rule = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; int index = 0; // rule 넘기는 index int value = 1; // 1 ~ n^2 int i = 0; int j = 0; while(va..

[프로그래머스/Lv.1] 덧칠하기

https://school.programmers.co.kr/learn/courses/30/lessons/161989 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { public int solution(int n, int m, int[] section) { int answer = 0; int paint = 0; // 완료된 영역 담을 수 for(int i : section) { if(i > paint) { paint = i + m - 1; answer++; } else continue; } return answer; } } 너무..

[프로그래머스/Lv.1] 카드 뭉치

https://school.programmers.co.kr/learn/courses/30/lessons/159994 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.*; class Solution { public String solution(String[] cards1, String[] cards2, String[] goal) { ArrayList c1List = new ArrayList(Arrays.asList(cards1)); ArrayList c2List = new ArrayList(Arrays.asList(cards2)..

[프로그래머스/Lv.1] 과일 장수

https://school.programmers.co.kr/learn/courses/30/lessons/135808 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 틀린 코드 1 import java.util.*; class Solution { public int solution(int k, int m, int[] score) { int answer = 0; int max = 0; ArrayList apple = new ArrayList(); ArrayList box = new ArrayList(); for(int n : score) apple.add(n)..

[프로그래머스/Lv.1] 명예의 전당 (1)

https://school.programmers.co.kr/learn/courses/30/lessons/138477 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 틀렸던 코드 1 import java.util.*; class Solution { public int[] solution(int k, int[] score) { int[] answer = new int[score.length]; int[] hof = new int[k]; for(int i = 0; i < k; i++) { hof[i] = score[i]; answer[i] = hof[0]; } ..

[프로그래머스/Lv.1] 콜라 문제

https://school.programmers.co.kr/learn/courses/30/lessons/132267 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { public int solution(int a, int b, int n) { int answer = 0; while(n >= a) { answer += n / a * b; n = n / a * b + n % a; } return answer; } } 2병을 1병으로 바꿔주는거 생각해보면 20 → 10 → 5 → 2(나눠떨어지는 4병으로 바꿈) + 1 → 1(나눠떨어..