본문 바로가기

Coding Test

(221)
[프로그래머스/자바] 양과 늑대 import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; class Solution { public int solution(int[] info, int[][] edges) { PathCalculator pathCalculator = new PathCalculator(info, edges); return pathCalculator.getMaxSheepCount(); } } class PathCalculator { private final int[] info; private final boolean[][] tree; private Path maxSheepCountPath; private Path firstPat..
[프로그래머스/자바] 다리를 지나는 트럭 import java.util.LinkedList; import java.util.Queue; class Solution { public int solution(int bridge_length, int weight, int[] truck_weights) { Queue bridge = new LinkedList(); for(int i=0; i weight){ sum -= bridge.poll(); if(sum + truck
[프로그래머스/자바] 더 크게 합치기 class Solution { public int solution(int a, int b) { String a1 = "" + a + b; String b1 = "" + b + a; a = Integer.parseInt(a1); b = Integer.parseInt(b1); return a >= b ? a : b; } }
[프로그래머스/자바] 배열 비교하기 class Solution { public int solution(int[] arr1, int[] arr2) { if(arr1.length > arr2.length) return 1; else if(arr1.length < arr2.length) return -1; else { int temp = 0; for(int i=0; i 0) return 1; else if(temp < 0) return -1; else return 0; } } }
[프로그래머스/자바] 공백으로 구분하기 2 class Solution { public String[] solution(String my_string) { String[] temp = my_string.trim().split(" "); int n = temp.length; for(String s : temp){ if(s.equals("")) n--; } String[] result = new String[n]; int idx = 0; for(String s : temp){ if(!s.equals("")) result[idx++] = s; } return result; } } class Solution { public String[] solution(String my_string) { return my_string.trim().split("[ ]+"..
[프로그래머스/자바] 배열의 원소만큼 추가하기 class Solution { public int[] solution(int[] arr) { int n = 0; for(int i : arr) n += i; int[] result = new int[n]; int index = 0; for(int num : arr){ for(int i=0; i
[백준/자바] 28014 - 첨탑 밀어서 부수기 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] arr = new int[n]; StringTokenizer st = new StringTokenizer(br.readLine..
[백준/자바] 2798 - 블랙잭 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integer.pa..