알고리즘 풀이/프로그래머스

삭제 부분에 직감적으로 실수할 것 같아서 짬시키는중 ============================================================ 코드 다시 엎어서 2번째 도전햇는데도 37점인가가 한계였다 솔직히 카카오 너무 악랄한 것 같다 테케라도 5개정도 던져주던가 구글에 레퍼런스 코드가 있기는 했지만 이런 구현은 풀이법이 아니라 안틀리고 짜는 것이 중요하기 때문에 스스로 할 수 있다고 판단되므로 나중에 재도전해야겠다 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172// 지금 하는 중인데 삭제부분..
문제를 접근하는 테크닉을 익혀야함 for문을 여러개쓰면 절대 안되고 가장 작은 것과 가장 큰 것을 더해서 limit와 비교해 클 때와 작을 때를 구분해서 2명을 보낼지 1명을 보낼지 끝까지 파악해줌 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26import java.util.*; class Solution { public int solution(int[] people, int limit) { int answer = 0; Arrays.sort(people); // for(int i=0; i
(a,b,c) - (e,f)의 조합을 (0,a,b,c) - (0,e,f)의 식으로 가상의 0개를 생성해주어 곱한 후에 옷을 하나도 안입는 경우인 (0) - (0)만 빼주는 생각을 참고 안했으면 절대 못풀었을 것임 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21import java.util.*; class Solution { public int solution(String[][] clothes) { HashMap hm = new HashMap(); for(int i=0; i
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20import java.util.*; class Solution { public boolean solution(String[] phone_book) { boolean answer = true; for(int i=0; i
stack클래스의 예외 옵션 때문에 어거지로 만든 쓰파게티코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50import java.util.*; class Solution { public String solution(String number, int k) { ArrayList arr = new ArrayList(); int index = 1; arr.add(number.charAt(0)); Character prev=arr.get(arr.size()-1); while(k>0 && index0){ prev..
우선순위 큐에 대한 개념이 필요한 문제 Integer에 대해서 오름차순으로 자동정렬되는 것만 알면 쉬움 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21import java.util.*; class Solution { public int solution(int[] scoville, int K) { PriorityQueue pq = new PriorityQueue(); int answer = 0; for(int i: scoville) pq.add(i); while(true){ if(pq.peek()>=K) break; if(pq.size()==1) return -1; else { pq.add(pq.poll() + (pq.poll())*2); answer++; ..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24import java.util.*; class Solution { public int solution(String arrangement) { String reArr = arrangement.replace("()","0"); Stack st = new Stack(); int answer = 0; for(int i=0; i
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47import java.util.*; public class Paper{ int num; int importance; public Paper ( int num, int importance ){ this.num = num; this.importance = importance; } } class Solution { public int solution(int[] priorities, int location) { LinkedList pp = new LinkedList(); int n..
트럭 클래스 선언 다리가 버틸 수 있는 남아있는 무게, 시간을 저장할 변수 선언 아직 다리를 지나지 못한 트럭 리스트 = outList 다리를 지나고 있는 트럭 리스트 = inList outList에 순서대로 트럭들을 저장해주고 outList와 inList가 모두 비어있을 때까지 반복문을 돌려줌 inList의 첫번째 성분(가장 먼저 다리에 들어간 트럭)의 distance가 0일 경우 가용무게를 그만큼 더해주고 요소를 제거해줌 그 다음 트럭이 들어올 수 있는지 체크한 후 가능하면 트럭을 들여보냄 time을 1초 더해줬기 때문에 전체트럭의 남은 거리를 discounting해줌 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28..
1일씩 지날 때마다 속도량(speeds)만큼 작업의 양(progresses)를 늘려줌 index는 0부터 시작하고 작업량이 100이상인지 하루가 지날때마다 체크해줌 현재 index가 100이상일 경우 배포시작임 배포시작부터 index를 늘려주면서 미완료될때까지 complete와 index를 늘려줌 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35import java.util.*; class Solution { public int[] solution(int[] progresses, int[] speeds) { List ans = new ArrayList(); int index=0; in..
배게
'알고리즘 풀이/프로그래머스' 카테고리의 글 목록 (10 Page)