Algorithms/- 프로그래머스
-
프로그래머스 - 크레인 인형뽑기 게임 [자바]Algorithms/- 프로그래머스 2022. 1. 30. 22:11
문제 링크 : 크레인 인형뽑기 게임 코딩테스트 연습 - 크레인 인형뽑기 게임 [[0,0,0,0,0],[0,0,1,0,3],[0,2,5,0,1],[4,2,4,4,2],[3,5,1,3,1]] [1,5,3,5,1,2,1,4] 4 programmers.co.kr 정답 import java.util.*; class Solution { public int solution(int[][] board, int[] moves) { int answer = 0; /* [ [0,0,0,0,0], [0,0,1,0,3], [0,2,5,0,1], [4,2,4,4,2], [3,5,1,3,1] ] 위와 같은 구조임 */ //stack에 넣고 pop answer + 2 하면 됨 //e.g. 1번 열은 각 배열의 인덱스 0임 //for문이..
-
프로그래머스 - 숫자 문자열과 영단어 [자바]Algorithms/- 프로그래머스 2022. 1. 30. 22:06
문제 링크 : 숫자 문자열과 영단어 코딩테스트 연습 - 숫자 문자열과 영단어 네오와 프로도가 숫자놀이를 하고 있습니다. 네오가 프로도에게 숫자를 건넬 때 일부 자릿수를 영단어로 바꾼 카드를 건네주면 프로도는 원래 숫자를 찾는 게임입니다. 다음은 숫자의 일부 자 programmers.co.kr 정답 import java.util.*; class Solution { public int solution(String s) { int answer = 0; Map numberMap = new HashMap(); numberMap.put("zero", 0); numberMap.put("one", 1); numberMap.put("two", 2); numberMap.put("three", 3); numberMap.pu..
-
프로그래머스 - 모의고사 [자바]Algorithms/- 프로그래머스 2022. 1. 30. 21:20
문제 링크 : 모의고사 코딩테스트 연습 - 모의고사 수포자는 수학을 포기한 사람의 준말입니다. 수포자 삼인방은 모의고사에 수학 문제를 전부 찍으려 합니다. 수포자는 1번 문제부터 마지막 문제까지 다음과 같이 찍습니다. 1번 수포자가 찍는 programmers.co.kr 정답 import java.util.*; class Solution { public int[] solution(int[] answers) { /* pickArr1 1,2,3,4,5 pickArr2 2,1,2,3,2,4,2,5 pickArr3 3,3,1,1,2,2,4,4,5,5 */ int[] pickArr1 = {1,2,3,4,5}; //5 int[] pickArr2 = {2,1,2,3,2,4,2,5}; //8 int[] pickArr3 ..
-
프로그래머스 - K번째 수 [자바]Algorithms/- 프로그래머스 2022. 1. 30. 20:34
문제 링크 : K번째 수 코딩테스트 연습 - K번째수 [1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3] programmers.co.kr 정답 import java.util.*; class Solution { public int[] solution(int[] array, int[][] commands) { int num = commands.length; int[] answer = new int[num]; //명령어 set만큼 돌면서 tempArr에 자른 배열을 담고 sort한다. int loop = 0; for(int[] command : commands){ int startIndex = command[0] - 1; int endIndex..
-
프로그래머스 - 네트워크 [자바]Algorithms/- 프로그래머스 2022. 1. 30. 18:15
문제 링크 : 네트워크 코딩테스트 연습 - 네트워크 네트워크란 컴퓨터 상호 간에 정보를 교환할 수 있도록 연결된 형태를 의미합니다. 예를 들어, 컴퓨터 A와 컴퓨터 B가 직접적으로 연결되어있고, 컴퓨터 B와 컴퓨터 C가 직접적으로 연결되어 있 programmers.co.kr 정답(Solution) - 20220209 다시 풀이 class Solution { public int solution(int n, int[][] computers) { int answer = 0; boolean[] v = new boolean[n]; for(int i=0; i
-
프로그래머스 - 타겟 넘버 [자바]Algorithms/- 프로그래머스 2022. 1. 30. 17:51
문제 링크 : 타겟 넘버 코딩테스트 연습 - 타겟 넘버 n개의 음이 아닌 정수들이 있습니다. 이 정수들을 순서를 바꾸지 않고 적절히 더하거나 빼서 타겟 넘버를 만들려고 합니다. 예를 들어 [1, 1, 1, 1, 1]로 숫자 3을 만들려면 다음 다섯 방법을 쓸 수 programmers.co.kr 정답 1. 재귀 : dfs함수가 int를 리턴하는 풀이 class Solution { public int solution(int[] numbers, int target) { int answer = 0; answer = dfs(numbers, 0, 0, target); return answer; } private int dfs(int[] numbers, int nodeNum, int sum, int target){ ..
-
프로그래머스 - 신규 아이디 추천 [자바]Algorithms/- 프로그래머스 2022. 1. 29. 23:11
문제 링크 : 신규 아이디 추천 코딩테스트 연습 - 신규 아이디 추천 카카오에 입사한 신입 개발자 네오는 "카카오계정개발팀"에 배치되어, 카카오 서비스에 가입하는 유저들의 아이디를 생성하는 업무를 담당하게 되었습니다. "네오"에게 주어진 첫 업무는 새로 programmers.co.kr 정답 class Solution { public String solution(String new_id) { //1단계 소문자 치환 new_id = new_id.toLowerCase(); //2단계 알파벳 소문자, 숫자, 빼기(-), 밑줄(_), 마침표(.)를 제외한 문자를 제거 String temp_id = ""; char[] charArr = new_id.toCharArray(); for(char id : charArr)..