본문 바로가기

Coding Test

(221)
[프로그래머스/자바] 콜라츠 추측 class Solution { public int solution(long num) { if (num == 1) return 0; int count = 0; while (count < 500) { num = num % 2 == 0 ? num /= 2 : num * 3 + 1; count++; if (num == 1) break; } return count != 500 ? count : -1; } }
[백준/자바] 1541 - 잃어버린 괄호 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); String[] arr = str.split("-"); int result = 0; for (int i = 0; i < arr.length; i++) { if (i == 0) { result += sum(arr[i]); } else { result -= sum(arr[i]); } } System.out.println(result); } private static int sum(String s) { int sum = 0; String[] arr ..
[백준/자바] 1931 - 회의실 배정 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.List; 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..
[백준/자바] 1744 - 수 묶기 import java.util.Collections; import java.util.PriorityQueue; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); PriorityQueue plusPq = new PriorityQueue(Collections.reverseOrder()); PriorityQueue minusPq = new PriorityQueue(); int zero = 0; int one = 0; for (int i = 0; i < N; i++) { int num = sc.nextI..
[백준/자바] 1715 - 카드 정렬하기 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.PriorityQueue; 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()); PriorityQueue pq = new PriorityQueue(); for (int i = 0; i < N; i++) { pq.add(I..
[백준/자바] 11047 - 동전 0 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 K = Integer.pa..
[리트코드/자바] 1603. Design Parking System class ParkingSystem { private int[] emptyArea = new int[3]; public ParkingSystem(int big, int medium, int small) { this.emptyArea[0] = big; this.emptyArea[1] = medium; this.emptyArea[2] = small; } public boolean addCar(int carType) { if (this.emptyArea[carType - 1] != 0) { this.emptyArea[carType - 1] -= 1; return true; } return false; } }
[백준/자바] 1300 - K번째 수 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int k = sc.nextInt(); long result = 0; long start = 1, end = k; while (start