Algorithms
-
프로그래머스 - 음양 더하기 [자바]Algorithms/- 프로그래머스 2022. 1. 30. 22:36
문제 링크 : 음양 더하기 코딩테스트 연습 - 음양 더하기 어떤 정수들이 있습니다. 이 정수들의 절댓값을 차례대로 담은 정수 배열 absolutes와 이 정수들의 부호를 차례대로 담은 불리언 배열 signs가 매개변수로 주어집니다. 실제 정수들의 합을 구하여 re programmers.co.kr 정답 class Solution { public int solution(int[] absolutes, boolean[] signs) { int answer = 0; int length = absolutes.length; for(int i = 0; i
-
프로그래머스 - 없는 숫자 더하기 [자바]Algorithms/- 프로그래머스 2022. 1. 30. 22:23
문제 링크 : 없는 숫자 더하기 코딩테스트 연습 - 없는 숫자 더하기 0부터 9까지의 숫자 중 일부가 들어있는 정수 배열 numbers가 매개변수로 주어집니다. numbers에서 찾을 수 없는 0부터 9까지의 숫자를 모두 찾아 더한 수를 return 하도록 solution 함수를 완성해주세요. programmers.co.kr 정답 import java.util.*; class Solution { public int solution(int[] numbers) { int answer = 0; /* numbers에 없는 숫자 모두 더해서 리턴 */ int[] pickNumbers = {0,1,2,3,4,5,6,7,8,9}; //정렬하고 Arrays.sort(numbers); for(int pick : pick..
-
프로그래머스 - 크레인 인형뽑기 게임 [자바]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 ..
-
LeetCode - path sum [Java]Algorithms/- LeetCode 2022. 1. 30. 21:02
문제 링크 : path sum Path Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 정답(Solution) /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, Tree..
-
프로그래머스 - 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