본문 바로가기

CodingTest46

코딩테스트 입문 - Day 17 숫자 찾기class Solution { public int solution(int num, int k) { String s = String.valueOf(num); String k1 = String.valueOf(k); int n = s.indexOf(k1); if(n == -1){ return -1; } return n+1; }}n의 배수 고르기import java.util.*;class Solution { public List solution(int n, int[] numlist) { List arr = new ArrayList(); for(int num : numlis.. 2025. 4. 27.
코딩테스트 입문 - Day 16 편지class Solution { public int solution(String message) { return message.length() * 2; }}가장 큰 수 찾기class Solution { public int[] solution(int[] array) { int max = array[0]; int idx = 0; for(int i =1; i max){ max = array[i]; idx = i; } } return new int[] {max, idx}; }}문자열 계산하기class Solution { public in.. 2025. 4. 27.
코딩테스트 입문 - Day 15 영어가 싫어요class Solution { public long solution(String numbers) { return Long.parseLong(numbers.replace("zero","0") .replace("one","1") .replace("two","2") .replace("three","3") .replace("four","4") .replace("five","5") .replace("six","6") .replace("seven","7") .replace("eight","8") .replace.. 2025. 4. 27.
코딩테스트 입문 - Day 14 가까운 수import java.util.*;class Solution { public int solution(int[] array, int n) { int min = 101; for(int i = 0; i Math.abs(array[i] - n)){ min = array[i]; }else if(Math.abs(min - n) == Math.abs(array[i] - n)){ min = Math.min(min, array[i]); } } return min; }}369 게임class Solution { public int solution(int or.. 2025. 4. 27.
프로그래머스 2레벨 - 무인도 문제 설명 메리는 여름을 맞아 무인도로 여행을 가기 위해 지도를 보고 있습니다. 지도에는 바다와 무인도들에 대한 정보가 표시돼 있습니다. 지도는 1 x 1크기의 사각형들로 이루어진 직사각형 격자 형태이며, 격자의 각 칸에는 'X' 또는 1에서 9 사이의 자연수가 적혀있습니다. 지도의 'X'는 바다를 나타내며, 숫자는 무인도를 나타냅니다. 이때, 상, 하, 좌, 우로 연결되는 땅들은 하나의 무인도를 이룹니다. 지도의 각 칸에 적힌 숫자는 식량을 나타내는데, 상, 하, 좌, 우로 연결되는 칸에 적힌 숫자를 모두 합한 값은 해당 무인도에서 최대 며칠동안 머물 수 있는지를 나타냅니다. 어떤 섬으로 놀러 갈지 못 정한 메리는 우선 각 섬에서 최대 며칠씩 머물 수 있는지 알아본 후 놀러갈 섬을 결정하려 합니다. 지.. 2025. 4. 20.
코딩테스트 입문 - Day 13 컨트롤 제트import java.util.ArrayList;class Solution { public int solution(String s) { String[] arr = s.split(" "); ArrayList al = new ArrayList(); int answer = 0; int size = arr.length; for(int i = 0; i 배열의 원소 길이class Solution { public int[] solution(String[] strlist) { int[] answer = new int[strlist.length]; for(int i = 0;i 중복된 문자 제거import java.. 2025. 4. 20.
728x90
반응형