[프로그래머스] 의상
🚨문제 설명💡푼 방법import java.util.HashMap;class Solution { public int solution(String[][] clothes) { int answer = 0; HashMap map = new HashMap(); for(int i = 0; i 1){ for(String cloth : map.keySet()){ w = map.get(cloth); w *= map.get(cloth); } answer += w; }else{ answer +..
- Coding-test/Java-Algorithm
- · 2026. 7. 1.
[프로그래머스] K번째 수
🚨문제 설명💡푼 방법import java.util.*;class Solution { public int[] solution(int[] array, int[][] commands) { ArrayList list = new ArrayList(); for(int i = 0; i set = new ArrayList(); for(int k = (commands[i][0])-1; k command 배열을 돌면서 배열 안에 들어있는 조건에 맞춰 수를 set에 더해주고 set을 기본 오름차순으로 정렬(Comparator.naturalOrder())한 후 command에 들어있는 마지막 조건에 해당하는 수를 list에 더해준다.*일반배열에서는 Arra..
- Coding-test/Java-Algorithm
- · 2026. 6. 14.
[프로그래머스] 같은 숫자는 싫어!
🚨문제 설명💡푼 방법import java.util.*;public class Solution { public int[] solution(int []arr) { int num = 1; //숫자가 변경되는 횟수 +1이 총 나와야하는 수의 개수 for(int i = 1; i 일단 나는 이전 숫자와 현재 숫자가 다를 경우에 num에 1을 더해주면서 answer 배열의 총 길이를 정해주었다.그리고 answer와 arr의 0번째는 무조건 같다고 판단했기 때문에 미리 넣어주고,그 다음 for문을 돌릴 때 j가 1부터 돌아가게해 이전 숫자와 비교하도록 했다.비교했을 때 다르면 answer배열에 넣어주고 다음 번호로 넘어가게 했고 아니면 j의 ..
- Coding-test/Java-Algorithm
- · 2026. 6. 14.
[프로그래머스] 폰켓몬
🚨문제 설명💡푼 방법import java.util.HashMap;class Solution { public int solution(int[] nums) { int answer = 0; HashMap map = new HashMap(); for(int n : nums){ map.put(n, map.getOrDefault(n, 0)+1); } int val = 0; for(int n : nums){ if(map.get(n) > 1){ val += 1; m..
- Coding-test/Java-Algorithm
- · 2026. 6. 10.
[프로그래머스] 완주하지 못한 선수
🚨문제 설명💡푼 방법나는 일단 for문으로 풀었는데 정답은 나오나 효율이 나오지 않아 실패로 떴다.class Solution { public String solution(String[] participant, String[] completion) { String answer = ""; for(int i = 0; i 🚧오답노트import java.util.HashMap;class Solution { public String solution(String[] participant, String[] completion) { String answer = ""; HashMap marathon = new H..
- Coding-test/Java-Algorithm
- · 2026. 6. 9.