본문 바로가기

Coding Test/프로그래머스

(138)
[프로그래머스/자바] 팩토리얼 class Solution { public int solution(int n) { int temp = 1; int num = 1; while(temp n) break; num++; } return num - 1; } }
[프로그래머스/자바] 모스부호 (1) class Solution { public String solution(String letter) { StringBuilder sb = new StringBuilder(); String[] morse = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."}; String[] bits = letter.split(" "); for(String bit : bits){ for(int i=0; i
[프로그래머스/자바] 신입사원 교육 import java.util.Arrays; class Solution { public int solution(int[] ability, int number) { for(int i=0; i
[프로그래머스/자바] 양과 늑대 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("[ ]+"..