본문 바로가기

Programmers

(188)
후보키 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 import java.util.*; class Solution { private static ArrayList allList = new ArrayList(); private static ArrayList key = new ArrayList(); public static void makeKey(String[][] relation, ..
[1차] 프렌즈4블록 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 class Solution { public int solution(int m, int n, String[] board) { int answer = 0; char[][] c_board = new char[m][n]; int[] pos = new int[n]; // 블록이 내려올 위치 boolean flag = true; // char array로 변환 for (int i = 0; i
점프와 순간 이동 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import java.util.*; public class Solution { public int solution(int n) { int ans = 0; while (n != 0) { if (n % 2 != 0) { n--; ans++; } n /= 2; } return ans; } } Colored by Color Scripter cs n까지 가는 경로에 규칙이 있다. n = 5 -> 1 - 2 - 4 - 5 n = 6 -> 1 - 2 - 3 - 6 n = 5000 -> 1 - 2 - 4 - 8 - 9 - 18 - 19 - 38 - 39 - 78 - 156 - 312 - 624 - 625 - 1250 - 2500 - 5000 역순으로 생각..
구명보트 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 import java.util.*; class Solution { public int solution(int[] people, int limit) { int answer = 0; int i = 0, li = limit; Deque dq = new ArrayDeque(); Arrays.sort(people); for (i = 0; i
영어 끝말잇기 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import java.util.*; class Solution { public int[] solution(int n, String[] words) { int[] answer = { 0, 0 }; Set set = new HashSet(); for (int i = 0; i 0 && words[i - 1].charAt(words[i - 1].length() - 1) != words[i].charAt(0)) { answer[0] = (i + 1) % n == 0 ? n : (i + 1) % n; // 번호 answer[1] = i / n + 1; // 차례 break; } else { set.add(words[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 class Solution { public int solution(int [][]board) { int answer = 0; int max = 0; // 1행, 1열 체크 for (int i = 0; i
[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 26 27 import java.util.*; class Solution { public int solution(int cacheSize, String[] cities) { int answer = 0; String[] newCities = new String[cities.length]; Queue queue = new LinkedList(); 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 class Solution { public int[] solution(int n) { int[] answer = {}; int[][] snail = new int[n][n]; int i, j; int cnt = 1, row = 0, col = 0; if(n == 1){ answer = new int[1]; answer[0] = 1; return answer; } while (col != n / 2) { // 세로 for (i = row; i