Algorithm

Algorithm/Programmers

[Programmers] LV2.n^2배열 자르기

// LV2.n^2배열 자르기 public static int[] solution_slice_array(int n, long left, long right) { int[] answer = new int[(int)(right-left+1)]; int idx = 0; for(long i = (long)Math.floor(left/n);i

Algorithm/Programmers

[Programmers] LV2. 주식가격

//LV2. 주식가격 public static int[] solution_stock_price(int[] prices) { int[] answer = new int[prices.length]; for(int i=0;i

Algorithm/Programmers

[Programmers] LV2. 예상 대진표

//LV2. 예상 대진표 public static int solution_expect_tournament(int n, int a, int b) { int answer = (int)Math.floor(Math.log(n)/Math.log(2)); while(Math.min(a,b) > n/2 || Math.max(a,b) n && Math.min(a,b) > n){ a -= n; b -= n; } } return answer; }

Algorithm/Programmers

[Programmers] LV2.이진변환 반복하기

//LV2.이진변환 반복하기 public static int[] solution_repeat_binary(String s) { int[] answer = new int[2]; answer[0] = 0; answer[1] = 0; while (s.length() > 1){ answer[0]++; answer[1] += Arrays.stream(s.split("")).filter(a->"0".equals(a)).count(); s = Integer.toBinaryString(s.replace("0","").length()); } return answer; }

Algorithm/Programmers

[Programmers] LV2. 타켓넘버

//LV2. 타켓넘버 public static int solution_target_number(int[] numbers, int target) { int answer = 0; int cnt = -1; while(++cnt < Math.pow(2,numbers.length)){ String bi = Integer.toBinaryString(cnt); int result_number = 0; for(int i=0;i

Algorithm/Programmers

[Programmers] LV2. 영어로 끝말잇기

//LV2. 영어로 끝말잇기 public static int[] solution_english_word_chain_game(int n, String[] words) { int cnt = 0; String prev_word = words[0]; while(++cnt < words.length){ if(prev_word.charAt(prev_word.length()-1)!=words[cnt].charAt(0)) break; if(0

Algorithm/Programmers

[Programmers] LV2. 행렬의 곱셈

// LV2. 행렬의 곱셈 public static int[][] solution_matrix_multiple(int[][] arr1, int[][] arr2) { int[][] answer = new int[arr1.length][arr2[0].length]; for(int i=0;i

Algorithm/Programmers

[Programmers] LV2. 다음 큰 숫자

//LV2. 다음 큰 숫자 public static int solution_next_max_int(int n) { int answer = 0; int cnt = Integer.toBinaryString(n).replace("0","").length(); while(0 < n++){ int cnt2 = Integer.toBinaryString(n).replace("0","").length(); if(cnt==cnt2) break; } return n; }

Bogass
'Algorithm' 카테고리의 글 목록 (3 Page)