diff --git "a/soyun/week27/\354\225\225\354\266\225.java" "b/soyun/week27/\354\225\225\354\266\225.java" new file mode 100644 index 0000000..6fea2a9 --- /dev/null +++ "b/soyun/week27/\354\225\225\354\266\225.java" @@ -0,0 +1,32 @@ +import java.util.*; + +class Solution { + + public List solution(String msg) { + ArrayList answer = new ArrayList<>(); + HashMap dict = new HashMap<>(); + + int dictIdx = 1; + for(int i='A'; i<='Z'; i++){ + dict.put( String.valueOf((char)i), dictIdx++) ; + } + + int idx = 0; + while(idx < msg.length()){ + StringBuilder w = new StringBuilder(); + while(idx < msg.length()){ + if(!dict.containsKey(w.toString() + msg.charAt(idx))){ + break; + } + w.append(msg.charAt(idx++)); + } + + answer.add(dict.get(w.toString())); + if(idx < msg.length()){ + dict.put(w.append(msg.charAt(idx)).toString(), dictIdx++); + } + } + + return answer; + } +} \ No newline at end of file diff --git "a/soyun/week27/\355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.java" "b/soyun/week27/\355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.java" index f5b6323..dbe3211 100644 --- "a/soyun/week27/\355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.java" +++ "b/soyun/week27/\355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.java" @@ -1,10 +1,10 @@ import java.util.*; class Solution { - + private char[][] board; private int popped; - + public int solution(int m, int n, String[] input) { board = new char[m][n]; popped = 0; @@ -16,11 +16,14 @@ public int solution(int m, int n, String[] input) { } return popped; } - + public boolean pop(int m, int n) { boolean isPopped = false; for (int i = 0; i < m - 1; i++) { for (int j = 0; j < n - 1; j++) { + if (board[i][j] == ' '){ + continue; + } if (isSame(i, j)) { board[i][j] = Character.toLowerCase(board[i][j]); board[i + 1][j] = Character.toLowerCase(board[i + 1][j]); @@ -32,18 +35,15 @@ public boolean pop(int m, int n) { } return isPopped; } - + public boolean isSame(int x, int y) { - if (board[x][y] == ' ') { - return false; - } char a = Character.toUpperCase(board[x][y]); char b = Character.toUpperCase(board[x + 1][y]); char c = Character.toUpperCase(board[x][y + 1]); char d = Character.toUpperCase(board[x + 1][y + 1]); return (a == b) && (a == c) && (a == d); } - + public void drag(int m, int n) { for (int i = m - 1; i >= 0; i--) { for (int j = 0; j < n; j++) { @@ -52,18 +52,13 @@ public void drag(int m, int n) { popped++; continue; } - if (i + 1 >= m) { - continue; - } - if (Character.isUpperCase(board[i + 1][j])) { - continue; - } - for (int next = i + 2; next < m; next++) { - if (Character.isUpperCase(board[next][j])) { - board[next - 1][j] = board[i][j]; - board[i][j] = ' '; - break; + int row = i + 1; + while(row < m) { + if (board[row][j] == ' ') { + board[row][j] = board[row - 1][j]; + board[row - 1][j] = ' '; } + row++; } } } diff --git "a/soyun/week28/\353\260\251\352\270\210\352\267\270\352\263\241.java" "b/soyun/week28/\353\260\251\352\270\210\352\267\270\352\263\241.java" new file mode 100644 index 0000000..0e3c317 --- /dev/null +++ "b/soyun/week28/\353\260\251\352\270\210\352\267\270\352\263\241.java" @@ -0,0 +1,68 @@ +import java.util.*; + +class Solution { + + static class Music implements Comparable{ + private int seq; + private String start; + private String end; + private String name; + private int playtime; + private String melody; + + public Music(int seq, String start, String end, String name, String melody) { + this.seq = seq; + this.start = start; + this.end = end; + this.name = name; + this.playtime = getTime(end) - getTime(start); + this.melody = getMelody(playtime, melody); + } + + public int getTime(String time) { + String[] s = time.split(":"); + return Integer.parseInt(s[0]) * 60 + Integer.parseInt(s[1]); + } + + public String getMelody(int playtime, String melody) { + int musicLength = melody.length(); + if (playtime < musicLength) { + return melody.substring(0, playtime); + } + int quotient = playtime / musicLength; + int remain = playtime % musicLength; + + return melody.repeat(quotient) + melody.substring(0, remain); + } + + public int compareTo(Music other) { + if (this.playtime == other.playtime) { + return Integer.compare(this.seq, other.seq); + } + return -1 * Integer.compare(this.playtime, other.playtime); + } + } + public String solution(String m, String[] musicinfos) { + PriorityQueue pq = new PriorityQueue<>(); + for (int i = 0; i < musicinfos.length; i++) { + String[] splitted = musicinfos[i].split(","); + String start = splitted[0]; + String end = splitted[1]; + String name = splitted[2]; + String melody = replace(splitted[3]); + pq.offer(new Music(i, start, end, name, melody)); + } + m = replace(m); + while (!pq.isEmpty()) { + Music music = pq.poll(); + if (music.melody.contains(m)) { + return music.name; + } + } + return "(None)"; + } + + public String replace(String melody) { + return melody.replace("C#", "c").replace("D#", "d").replace("F#", "f").replace("G#", "g").replace("A#", "a"); + } +} \ No newline at end of file diff --git "a/soyun/week28/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" "b/soyun/week28/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" new file mode 100644 index 0000000..4a5e231 --- /dev/null +++ "b/soyun/week28/\354\247\225\352\262\200\353\213\244\353\246\254_\352\261\264\353\204\210\352\270\260.java" @@ -0,0 +1,26 @@ +import java.util.*; + +class Solution { + + public int solution(int[] stones, int k) { + + PriorityQueue q = new PriorityQueue<>((o1, o2) -> Integer.compare(o1[0], o2[0])); + + for (int i = 0; i < k - 1; i++) { + q.offer(new int[]{-1 * stones[i], i}); + } + int min = Integer.MAX_VALUE; + for (int i = k - 1; i < stones.length; i++) { + while (!q.isEmpty()) { + int[] cur = q.peek(); + if (cur[1] > i - k) { + break; + } + q.poll(); + } + q.offer(new int[]{-1 * stones[i], i}); + min = Math.min(min, -1 * q.peek()[0]); + } + return min; + } +} \ No newline at end of file