목록분류 전체보기 (150)
코딩응급실
class Solution { public String solution(int num) { return num%2==0 ? "Even" : "Odd"; } public static void main(String[] args) { int num = 3; Solution sol = new Solution(); String result = sol.solution(num); System.out.println(result); } }
class Solution { public int[] solution(int[] arr) { if (arr.length == 1) { return new int[]{-1}; } int min = arr[0]; for (int i = 1; i < arr.length; i++) { if (arr[i] < min) { min = arr[i]; } } int[] answer = new int[arr.length - 1]; int index = 0; for (int i = 0; i < arr.length; i++) { if (arr[i] != min) { answer[index++] = arr[i]; } } return answer; } public static void main(String[] args) { i..
import java.util.*; class Solution { public String solution(String[] participant, String[] completion) { String answer = ""; HashMap hp = new HashMap(); for (String player : participant) { hp.put(player, hp.getOrDefault(player, 0) + 1); } for (String player : completion) { hp.put(player, hp.get(player) - 1); } for (String key : hp.keySet()) { if (hp.get(key) != 0){ answer = key; } } return answe..
import java.util.*; class Solution { public int[] solution(int[] array, int[][] commands) { int[] answer = new int[commands.length]; ArrayList list = new ArrayList(); for (int i = 0; i < commands.length; i++) { for (int j = commands[i][0]; j
import java.util.*; class Solution { public int[] solution(int[] answers) { int[] first = {1,2,3,4,5}; // 5개씩 반복 int[] second = {2,1,2,3,2,4,2,5}; // 8개씩 반복 int[] third = {3,3,1,1,2,2,4,4,5,5}; // 10개씩 반복 int[] score = {0,0,0}; // 각 수포자들의 점수 // 수포자들의 점수 계산 for(int i=0; i
import java.util.HashSet; class Solution { public int solution(int n, int[] lost, int[] reserve) { int answer = 0; /* 학생들의 번호는 체격 순으로 매겨져 있어, 바로 앞번호의 학생이나 바로 뒷번호의 학생에게만 체육복을 빌려줄 수 있습니다. 예를 들어, 4번 학생은 3번 학생이나 5번 학생에게만 체육복을 빌려줄 수 있습니다 3 5 (가능) */ HashSet resSet = new HashSet(); HashSet loSet = new HashSet(); for(int i: reserve) { resSet.add(i); } for(int i: lost) { if(resSet.contains(i)) { resSet...

신규 가입자: "에라이 고인물 전치네! 안 해!" 개발자: "각 스테이지마다 실패율을 구해보자." 이런 뜬금없는 억지 전개가 담긴 문제를 풀어야 하다니... import java.util.*; class Solution { public int[] solution(int N, int[] stages) { int total = stages.length; double[] percent = new double[N]; HashMap countMap = new HashMap(); //각각의 수들의 개수를 맵에 해시맵에 저장 for (int num : stages) { countMap.put(num, countMap.getOrDefault(num, 0) + 1); } // 1 ~ N 까지만 보면 된다. for (in..

이것이 moves 배열에 있는 숫자에 따라서 펑펑! 사라지면, 아래와 같이 나올 것이다. 1, 5, 3, 5, 1, 2, 1, 4 어피치, (공룡, (네오, 네오)펑!, 공룡)펑!, 무지, x, 어피치 결과: 4개를 터뜨렸다. import java.util.*; class Solution { public int solution(int[][] board, int[] moves) { int answer = 0; Stack stack = new Stack(); for (int move : moves) { for (int y = 0; y < board.length; y++) { int num = board[y][move - 1]; if (num != 0) { // 펑! if (!stack.isEmpty() &&..