본문 바로가기

Coding Test

(221)
[백준/자바] 2343 - 기타 레슨 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); int[] arr = new int[N]; int start = 0; int end = 0; for (int i = 0; i < N; i++) { arr[i] = sc.nextInt(); if (start < arr[i]) start = arr[i]; end += arr[i]; } while (start middle) { count++; sum = 0; } sum += arr[i]; } if (sum != 0..
[백준/자바] 1316 - 그룹 단어 체커 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int result = 0; for (int i = 0; i < N; i++) { char[] arr = sc.next().toCharArray(); int[] index = new int[26]; for (int j = 0; j < 26; j++) { index[j] = -1; } boolean isGroupWord = true; for (int k = 0; k < arr.length; k++) { if (index[arr[k] - 97] != ..
[백준/자바] 10814 - 나이순 정렬 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..
[리트코드/자바] 1920. Build Array from Permutation class Solution { public int[] buildArray(int[] nums) { int[] result = new int[nums.length]; for (int n : nums) { result[n] = nums[nums[n]]; } return result; } }
[리트코드/자바] 1929. Concatenation of Array class Solution { public int[] getConcatenation(int[] nums) { int[] result = new int[nums.length * 2]; System.arraycopy(nums, 0, result, 0, nums.length); System.arraycopy(nums, 0, result, nums.length, nums.length); return result; } } class Solution { public int[] getConcatenation(int[] nums) { int[] result = new int[nums.length * 2]; for (int i = 0; i < nums.length; i++) { result[i] = nums[i]; re..
[프로그래머스/자바] 문자열 내림차순으로 배치하기 import java.util.Arrays; class Solution { public String solution(String s) { char[] arr = s.toCharArray(); Arrays.sort(arr); return new StringBuilder(new String(arr)).reverse().toString(); } }
[프로그래머스/자바] 행렬의 덧셈 class Solution { public int[][] solution(int[][] arr1, int[][] arr2) { int[][] answer = arr1; for (int i = 0; i < arr1.length; i++) { for (int j = 0; j < arr1[0].length; j++) { answer[i][j] += arr2[i][j]; } } return answer; } }
[백준/자바] 1167 - 트리의 지름 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { static boolean[] visited; static int[] distance; static ArrayList[] arr; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int V = Integer.parseInt(br.readLine()); arr = new ArrayLi..