분류 전체보기
-
프로그래머스 - 완주하지 못한 선수알고리즘 2024. 5. 2. 12:08
import java.util.*;class Solution { public String solution(String[] participant, String[] completion) { String answer = ""; Map map = new HashMap(); for (String player : participant) map.put(player, map.getOrDefault(player, 0) + 1); for(String player : completion) { if(map.get(player) == 1) map.remove(player); else { ..
-
프로그래머스 - 로또의 최고 순위와 최저 순위알고리즘 2024. 5. 2. 11:20
import java.util.*;class Solution { public int[] solution(int[] lottos, int[] win_nums) { int[] answer = new int[2]; int zero = 0, cnt = 0; // 0의 갯수, 맞춘 갯수 for(int i = 0; i 0의 갯수와 맞춘 갯수를 구해 최고 순위와 최저 순위를 구하는 문제입니다.하나도 맞추지 못 한거나 하나만 맞췄을 때 6위인 것만 예외로 구하면 어렵지 않은 문제였습니다.
-
프로그래머스 - 다트 게임알고리즘 2024. 5. 1. 15:58
import java.util.*;class Solution { public int solution(String dartResult) { int answer = 0; List scores = new ArrayList(); StringBuilder sb = new StringBuilder(); int score = 0; for(char c : dartResult.toCharArray()) { if(Character.isDigit(c)) { // 숫자일 때 점수 구하기 sb.append(c); } else if (c == 'S' || c == 'D'||..
-
프로그래머스 - 실패율알고리즘 2024. 4. 29. 18:24
import java.util.*;class Solution { public int[] solution(int N, int[] stages) { int[] challenge = new int[N + 1]; // 도전한 사람 수 double[] fail = new double[N + 1]; // 실패율 int num = stages.length; // 총 사용자 수 Map map = new HashMap(); for(int stage : stages) { for(int i = 0; i result = new ArrayList(map.keySet()); // 내림차순 정렬 ..
-
프로그래머스 - 덧칠하기알고리즘 2024. 4. 29. 11:33
class Solution { public int solution(int n, int m, int[] section) { int answer = 0; boolean[] wall = new boolean[n]; for(int i = 0; i 길이가 n인 벽을 배열로 선언해주고, 새롭게 덧칠을 해야하는 부분을 true로 변경 후, wall 배열을 탐색하여 true인 부분부터 m만큼 색을 다시 덧칠해주고 횟수를 증가시킵니다.이 때, 배열의 크기를 넘길 수 있으므로 조건을 걸어줍니다.
-
프로그래머스 - 모의고사알고리즘 2024. 4. 21. 08:11
import java.util.*; class Solution { public int[] solution(int[] answers) { int[] p1 = {1, 2, 3, 4, 5}; int[] p2 = {2, 1, 2, 3, 2, 4, 2, 5}; int[] p3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; int[] scores = new int[3]; int max = 0; List list = new ArrayList(); for(int i = 0; i < answers.length; i++) { if(answers[i] == p1[i % p1.length]) scores[0]++; if(answers[i] == p2[i % p2.length]) scores[1]++; if(an..
-
프로그래머스 - 명예의 전당알고리즘 2024. 4. 17. 01:08
import java.util.*; class Solution { public int[] solution(int k, int[] score) { int[] answer = new int[score.length]; PriorityQueue priorityQueue = new PriorityQueue(); int temp = 0; for(int i = 0; i k) { priorityQueue.poll(); } answer[i] = priorityQueue.peek(); } return answer; } } 명예의 전당 목록의 k 순위의 가장 최하위 점수를 찾는 문제입..
-
프로그래머스 - 콜라 문제알고리즘 2024. 4. 14. 00:45
class Solution { public int solution(int a, int b, int n) { int answer = 0; while(n >= a) { int bottle = (n / a) * b; int remainder = n % a; answer += bottle; n = bottle + remainder; } return answer; } } 마트에 콜라병을 가져갔을 때 받을 수 있는 병의 갯수(bottle)를 구하고, 가져가고 남은 갯수(remainder)를 구하여 값을 더 해주고 더 이상 나눌 수 없을 때 ( 콜라병을 받을 수 없는 ) 까지 반복하여 갯수를 구했습니다.