본문 바로가기

코딩테스트/프로그래머스 1단계44

프로그래머스 1단계 - 나누어 떨어지는 숫자 배열 https://programmers.co.kr/learn/courses/30/lessons/12910 코딩테스트 연습 - 나누어 떨어지는 숫자 배열 array의 각 element 중 divisor로 나누어 떨어지는 값을 오름차순으로 정렬한 배열을 반환하는 함수, solution을 작성해주세요. divisor로 나누어 떨어지는 element가 하나도 없다면 배열에 -1을 담아 반환하 programmers.co.kr import java.util.*; class Solution { public int[] solution(int[] arr, int divisor) { //만약 arr에 {2, 9, 3, 6, 11}이 있다. //divisor가 3이라면 {3, 6, 9}만 출력한다. //divisor가 4라면 .. 2021. 4. 19.
프로그래머스 1단계 - 모의고사 https://programmers.co.kr/learn/courses/30/lessons/42840 코딩테스트 연습 - 모의고사 수포자는 수학을 포기한 사람의 준말입니다. 수포자 삼인방은 모의고사에 수학 문제를 전부 찍으려 합니다. 수포자는 1번 문제부터 마지막 문제까지 다음과 같이 찍습니다. 1번 수포자가 찍는 programmers.co.kr import java.util.*; class Solution { public int[] solution(int[] answers) { int[] supo1 = {1, 2, 3, 4, 5}; int[] supo2 = {2, 1, 2, 3, 2, 4, 2, 5}; int[] supo3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; int supo1a.. 2021. 4. 18.
프로그래머스 1단계 - K번째수 https://programmers.co.kr/learn/courses/30/lessons/42748 코딩테스트 연습 - 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[] answer = new int[commands.length]; for(int i=0; i 2021. 4. 18.
프로그래머스 1단계 - 체육복 https://programmers.co.kr/learn/courses/30/lessons/42862 코딩테스트 연습 - 체육복 점심시간에 도둑이 들어, 일부 학생이 체육복을 도난당했습니다. 다행히 여벌 체육복이 있는 학생이 이들에게 체육복을 빌려주려 합니다. 학생들의 번호는 체격 순으로 매겨져 있어, 바로 앞번 programmers.co.kr import java.util.*; class Solution { public int solution(int n, int[] lost, int[] reserve) { //전체 학생 수에서 체육복을 잃어버린 아이들의 수를 빼면 체육복을 가지고 있는 아이들이 남는다. int answer = n - lost.length; //체육복을 잃어버린 학생이 reserve에 포.. 2021. 4. 16.
프로그래머스 1단계 - 두개 뽑아서 더하기 https://programmers.co.kr/learn/courses/30/lessons/68644 코딩테스트 연습 - 두 개 뽑아서 더하기 정수 배열 numbers가 주어집니다. numbers에서 서로 다른 인덱스에 있는 두 개의 수를 뽑아 더해서 만들 수 있는 모든 수를 배열에 오름차순으로 담아 return 하도록 solution 함수를 완성해주세요. 제한 programmers.co.kr import java.util.*; class Solution { public int[] solution(int[] numbers) { ArrayList arr = new ArrayList(); for(int i=0; i 2021. 4. 15.
프로그래머스 1단계 - 크레인 인형뽑기 게임 https://programmers.co.kr/learn/courses/30/lessons/64061 코딩테스트 연습 - 크레인 인형뽑기 게임 [[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) { //board에는 어떤 2차원 배열의 값이 들어가있다. //moves는 어떤위치의 인형을 뽑을지의 순서이다. //moves[0]의 값이 1이라면 board[0][0]부터 시작한다. //board[0][0]이 0이기때문에 board[0].. 2021. 4. 14.
반응형