[프로그래머스, Java] 크레인 인형뽑기 게임
·
CodingTest/Programmers
💡풀이import java.util.ArrayDeque;import java.util.Deque;class Solution { public int solution(int[][] board, int[] moves) { // 각 열을 스택으로 관리하기 위한 Deque 배열 Deque[] stacks = new ArrayDeque[board.length]; for(int i = 0; i (); } // 2차원 배열 board를 각 열에 해당하는 스택으로 변환 for(int i = board.length - 1; i >= 0; i--) { for(int j = 0; j basket = new ArrayDequ..
[프로그래머스, Java] 햄버거 만들기
·
CodingTest/Programmers
❌풀이 1// 배열을 한문자로 만든다// 1231을 replace한다// 기존 문자와 replace한 문자의 길이차이 / 4 를 해서 answer 에 저장한다// 기존과 길이차이가 나지 않을때까지 반복한다import java.util.Arrays;import java.util.stream.Collectors;class Solution { // 실패한 풀이 public int solution(int[] ingredient) { String recipe = "1231"; String burgers = Arrays.stream(ingredient).mapToObj(String::valueOf).collect(Collectors.joining()); String pac..
[프로그래머스, Java] 숫자 짝꿍
·
CodingTest/Programmers
💡풀이 1import java.util.*;class Solution { // 문자열을 받아 각 숫자의 개수를 세어 Map으로 반환하는 함수 private Map getNumberMapByStr(String str) { Map map = new HashMap(); // 문자열을 한 글자씩 숫자로 변환하여 개수를 셈 for(String s : str.split("")) { int n = Integer.parseInt(s); map.put(n, map.getOrDefault(n, 0) + 1); } return map; } public String solution(String X, S..
[프로그래머스, Java] 체육복
·
CodingTest/Programmers
💡풀이import java.util.Arrays;class Solution { public int solution(int n, int[] lost, int[] reserve) { int[] students = new int[n + 1]; Arrays.fill(students, 1); students[0] = -1; for(int number : reserve) { students[number]++; } for(int number : lost) { students[number]--; } for(int number = 1; number 1) { ..
[프로그래머스, Java] 완주하지 못한 선수
·
CodingTest/Programmers
💡풀이// 1. map에 담고 하나씩 차감한다?// 마지막 남은애는 어떻게 찾게// 2. 그냥 set에 넣는다?// 중복이 사라져버림// 3. 1명 적은 completion을 맵에 집어넣는다 // participant를 순차적으로 제거하는데 만약 map에 존재하지않으면 해당 이름을 반환한다import java.util.HashMap;import java.util.Map;class Solution { public String solution(String[] participant, String[] completion) { Map map = new HashMap(); for(String player : completion) { map.put(player, m..
[프로그래머스, Java][PCCE 기출문제] 9번 / 이웃한 칸
·
CodingTest/Programmers
💡풀이class Solution { public int solution(String[][] board, int h, int w) { int n = board.length; int count = 0; int[] dh = new int[]{1, -1, 0, 0}; int[] dw = new int[]{0, 0, 1, -1}; for(int i = 0; i GitHub - okjunghyeon/Programmers_CodingTest: 프로그래머스 관련 코딩테스트 문제를 풀이한 저장소입니다.프로그래머스 관련 코딩테스트 문제를 풀이한 저장소입니다. Contribute to okjunghyeon/Programmers_CodingTest dev..