CodingTest

·CodingTest
계수정렬 알고리즘을 이용해야 주어진 메모리, 시간에 안에 할 수 있다. import java.io.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int repeat_count = Integer.parseInt(br.readLine()); int[] array = new int[10001]; for (int i = 0; i < repeat_c..
·CodingTest
스택을 이용해서 '(' 가 나오면 바로 push를 해주고 ')'가 나오면 pop을 해서 '('가 있는지 확인한다. 이러한 알고리즘을 생각하면서 코딩하면 쉽게 된다. No가 나오는 경우의 수 case 1: '('가 스택에 없는데 ')'만 있는경우 - stackoverflow -> 예외처리를 해서 false로 바꿔줌 case 2: '('가 스택에 남아있는경우 - 스택이 비어있지 않으면 No import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Stack; public class Main { public static void main(String[] args) thro..
·CodingTest
브루트포스 알고리즘 문제 - 전체 경우의 수를 보는 알고리즘 import java.io.*; import java.util.ArrayList; import java.util.Collections; public class Main { static char[][] board; static int count; static char stan_change(char x){ if(x=='W') return 'B'; else return 'W'; } static int board_cutting(char[][] boards){ int b_count=0; int w_count=0; char bStart='B'; char wStart='W'; for (int i = 0; i < 8; i++) { for (int j = 0;..
·CodingTest
현재까지 푼 코딩테스트 중에 난이도도 제일 높고 시간도 제일 오래 걸린 문제였다. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { static long[] arrays; static long key; static long Binary_Search(long start, long end) { if (start > end) return -1; long mid = (start + end) / 2; long total = 0; for (long x : arrays) { total += x / mid; } if (total >= key) { return Math...
동그리담
'CodingTest' 카테고리의 글 목록 (6 Page)