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

문제에서 하라는대로 하면 되긴 하는데 좀 그냥 헷갈림..ㅠ 마지막 부분 UInfo Class에서 생성자에서 parameter를 isMatched가 아니라 isMached로 잘못써서 자꾸 false값만 나오길래 곤경에 빠졌었다.. this.isMatched = isMatched가 this.isMatched = this.isMatched가 된듯.. 그러니 boolean기본값인 false만 계속 박혔었던 것 같다 class Solution { public String solution(String p) { return divideUV(new StringBuilder(p)).toString(); } private StringBuilder divideUV(StringBuilder sb){ if(sb.length()..
1. orders배열의 order들을 toCharArray()로 char[]로 변환 후 Arrays.sort(char[]) 후에 String.valueOf(char[])로 알파벳 순으로 정렬된 주문 요리순서로 바꿈 (이거 안해주면 나중에 map으로 누적시킬 때 "XY" "YX" 이런 요리 조합이 따로 누적됨) 2. comb 메서드는 계속 하면 indexOutOfRange뜨다가 결국 완성함 3. combOrder 메소드의 마지막 parameter인 int PreIdx가 핵심이었는데 이걸 안해주면 XYZ의 조합에서 ZZZ AB 조합에서 BB 이런 것이 나옴 4. mostOrderNum int[]을 통해 n개 조합의 최다 주문된 횟수를 mostOrderNum[n]에 Math.max를 통해 계속 갱신시켜줄것 i..
구현인데 행렬회전이 안 익숙해서 좀 오래 걸리기도하고 무수히 많은 indexOutOfRange랑 악수했다 이거 matrix문제 풀 때는 2차원 배열 표시할 때 (x,y)로 하지 말고 (r,c)으로 해야 안 헷갈리는 것 같다 (x,y)로 하면 arr[y][x]로 해야되서 더 헷갈려짐..ㅠㅠ 나중에는 종이에 그림에 미리 그려놓은 다음에 index부분에서는 exception안나게 해야겠다.. 맨날터지네 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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58..
1234567891011121314151617181920import java.util.*; class Solution{ public int solution(String s) { Stack st = new Stack(); for(int i=0; i
12345678910111213141516171819class Solution { public int solution(int[] numbers, int target) { return DFS(numbers, target, 0, 0); } public int DFS(int[] numbers, int target, int preOrder, int total){ if(preOrder == numbers.length){ // System.out.println(preOrder+" "+total); if(total==target) return 1; else return 0; } return DFS(numbers, target, preOrder+1, total+numbers[preOrder])+ DFS(numbers,..
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 import java.util.*; class Solution { public int[] solution(int[] progresses, int[] speeds) { List list = new ArrayList(); int i = 0; while(iinteger.intValue()).toArray(); int[] answer = listToArray(list); return answer; } public int requiredDays(int progress, int speed){ ..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import java.util.*; class Solution { public String solution(int n) { String[] str124 = new String[]{"4","1","2"}; StringBuilder sb = new StringBuilder(); while(n>0){ sb.append(str124[n%3]); n = (n-1)/3; } return sb.reverse().toString(); } } Colored by Color Scripter cs Line:10 n=(n-1)/3; 여기 논리가 진짜 말도 안된다..ㅠ충격 먹엇음 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19..
1. 문제에서 주어진 예제의 입출력에서 단위 unit의 형태를 가진 사각형을 찾은 후에 이것이 w, h의 최대공약수와 관련이 있다는 것을 발견함 2. 그 후에는 최대공약수를 구하는 메소드와 unit사각형내의 비어 있는 사각형의 개수를 unit사각형의 가로와 세로를 활용하여 규칙을 찾아내야 하는데 아무리 머리를 굴려봐도 나오지 않음 이 규칙을 발견하더라도 최대공약수를 구하는 메소드는 구글링을 하지 않는 이상 스스로 못짬 (unit의 빈 사각형 갯수) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 class Solution { public long solution(long w, long h) { long gcd = gcd(w,h); long answer = w*h - ..
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 class Solution { public int solution(String s) { int answer = s.length(); // s.length()/2까지만 하면 됨 for(int i=1; i1) compressedNum+=(Math.log10(accumNum)+1); // System.out.println(i+" "+compressedNum); answer = Math.min(answer, compressedNum); } return answer; } } Colored by Color Scripter cs 1 2 3 4 5 6 7..
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354import java.util.*; class Solution { public int[] solution(String[] id_list, String[] report, int k) { Map userMap = new HashMap(); for(String id : id_list) userMap.put(id, new User(id)); // System.out.println(userMap.size()); List bannedIdList = new ArrayList(); for(String r : report){ String[] st..
배게
'알고리즘 풀이/프로그래머스' 카테고리의 글 목록 (4 Page)