목록Algorithm (58)
개발일기
올바른 괄호 (스택/큐) 전형적인 Stack 문제이다.그다지 어렵지 않았지만, 최대한 인덴트 1을 넘기지 않으려고 노력하였고, 그에따라서 processCharacter라는 메소드를 만들어서 문제를 풀었다.또한 IllegalArgumentException을 사용하여 에러가 나왔을 때, try -catch문을 사용하여 에러를 잡고 이를 false로 던져주도록 만들었다. 마지막 return 은 stack.isEmpty()를 통해서 비어있는지 확인해서 리턴했다. import java.util.*;class Solution { boolean solution(String s) { Stack stack = new Stack(); try{ s.chars() ..
Arrays.sort(times);long start = 1;long end = (long) times[times.length-1] * n;long answer = end; - 최소한 일초가 걸리기에 start = 1 대입해주었다- end는 최악의 시간을 넣어주어야하기에 가장 오래 걸리는 시간으로 해주었다. - 여기서 Arrays.sort 를 해준 이유는 최악시간이 맨 뒤에 없을 수도 있기에 해주었다. while (start - while(start- mid = (start + end) / 2 중간값을 구합니다. - 각 심사관이 mid시간 동안 몇명을 처리할 수 있는지 사람의 수를 계산합니다. - 각 심사관이 처리할 수 있는 수를 sum에 저장합니다. if (sum >= n) { answer..
1. info 정보를 '-'를 추가하여 모든 조합을 가져와주어야함. java backend junior pizza 150위에를 조합하였을 때, 아래와 같이 나온다. ```-backendjunior-java--pizzajavabackend-----pizza-backend---backend-pizzajava----backendjuniorpizzajavabackendjuniorpizza--junior-javabackend-pizza----java-juniorpizzajava-junior-javabackendjunior---juniorpizza 조합 public static void combination(String str, String[] info, int depth){ if(de..
1.이진 탐색의 기준을 거리로 잡는다. 2.기준 값보다 사이의 있는 값이 작을 시, 바위를 삭제해준다.3.맨마지막 바위 위치도 거리를 잰다. 4.큰 횟수를 기준으로 mid를 줄일지 늘리지 정해준다. import java.util.*;class Solution { public int solution(int distance, int[] rocks, int n) { int answer = 0; Arrays.sort(rocks); int start = 0; int end = distance; int result = distance; while(start n) break;..
package src.Week15.p12100;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class Main { static int n, answer, map[][], copy[][]; static int[] direct; static boolean[][] visit; static int[] dx = {0, -1, 0, 1}; // 우, 상, 좌, 하 static int[] dy = {1, 0, -1, 0}; public static void main(String[] args) thro..

import java.util.Arrays;class Solution { public int solution(int[] citations) { int answer = 0; Arrays.sort(citations); for(int h = citations.length; h>=1; h--) { if(isValid(citations, h)) return h; } return 0; } private boolean isValid(int[] citations, int h) { int index = citations.length - h; retu..
자바 문제 풀이 1. 체크를 해주기 위한 배열을 만들어주었다. 100 + 99 를 더해준다고 가정했을 때, 200을 선언해도 충분하다. 2. 이중 포문을 돌면서 각각의 경우의 수를 더해주어 flag 를 태워서 flag true를 만들어준다. 3. Collections.sort를 사용해여. list를 정렬해준다. 그 후, list 반환. import java.util.*;class Solution { public List solution(int[] numbers) { List list = new ArrayList(); boolean []flag = new boolean[200]; for(int i=0; i 파이썬 문제 풀이 def solution(numbe..
이제부터 나는 이도류가 될 것이다. Why? Python에 대한 오픈소스가 너무 많고 개발이 더 편해보인다. 그래서 이도류를 택하기로 했다. k 번째수 자바 코드 import java.util.*;class Solution { public int[] solution(int[] array, int[][] commands) { int[] answer = new int[commands.length]; for(int i=0;i 1. commands [i][0]에서 start를 가져온다.2. commands [i][1]에서 end를 가져옴. Arrays.copyOfRange(array, start-1, end)를 통해서 배열을 복사해. Arrays.sort를 통해..