[프로그래머스, 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..
[프로그래머스, Java] 대충 만든 자판
·
CodingTest/Programmers
💡풀이import java.util.HashMap;import java.util.Map;class Solution { public int[] solution(String[] keymap, String[] targets) { Map map = new HashMap(); // keymap을 순회하며 각 알파벳의 가장 적게 누르는 횟수를 저장함 // ex) "BACAD" -> ('A', 2) 단 기존에 저장되어있던 'A' 횟수보다 작을 경우 for(String s : keymap) { for(int i = 0; i GitHub - okjunghyeon/Programmers_CodingTest: 프로그래머스 관련 코딩테스트 문제를 풀..
[프로그래머스, Java] 문자열 나누기
·
CodingTest/Programmers
💡풀이class Solution { public int solution(String s) { int answer = 0; // A 라벨: continue A를 통해 이 while 루프의 처음으로 바로 돌아가기 위함 A: while(!s.isEmpty()) { for(int i = 0; i 📖새로 배운 부분💡replace와 replaceAllreplace : 바꾸려는 대상이 고정된 문자열일 때 (예: "apple", " ", "\n")replaceAll : 패턴으로 문자를 찾고 싶을 때 (예: "[0-9]" "[^p]" 등등) 관련 정리 글 [java] replace()와 replaceAll()의 차이점replace()와 r..
[프로그래머스, Java] 둘만의 암호
·
CodingTest/Programmers
💡풀이/** * s를 각 문자를 기준으로 순회한다 * * s.charAt을 index만큼 이동해 나간다 * 만약 이동할 문자가 z 일경우 a로 간다 * 만약 이동할 문자가 skip에 포함된다면 횟수를 세지않고 넘어간다 * 이동 완료된 문자는 저장한다 * * 순회 후 저장된 모든 문자를 문자열로 바꿔 return 한다 */class Solution { public String solution(String s, String skip, int index) { StringBuilder sb = new StringBuilder(); for(char c : s.toCharArray()) { int count = 0; while(count 📖새..
[프로그래머스, Java] 로또의 최고 순위와 최저 순위
·
CodingTest/Programmers
💡풀이import java.util.Arrays;import java.util.List;import java.util.stream.Collectors;class Solution { public int[] solution(int[] lottos, int[] win_nums) { // 1. 0의 개수를 센다 int zeroCount = (int) Arrays.stream(lottos) .filter(e -> e == 0) .count(); // 2. contains 메서드 사용을 위해 당첨 번호를 리스트로 변환 List winList = Arrays.stream(win_nums) ..
[프로그래머스, Java][1차] 다트 게임
·
CodingTest/Programmers
💡풀이import java.util.Arrays;class Solution { public int solution(String dartResult) { // 점수(숫자)만 뽑아 int[]로 변환 int[] numbers = Arrays.stream(dartResult.split("[^0-9]")) // 숫자가 아닌 문자로 split .filter(e -> !e.isBlank()) // 빈 토큰 제거 .mapToInt(Integer::parseInt) // int 변환 .toArray(); // 점수를 제외한 옵션(S·D·T·*·#)만 String[]..