목록Algorithm/Programmers (15)
in.add()
문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/42579 코딩테스트 연습 - 베스트앨범 스트리밍 사이트에서 장르 별로 가장 많이 재생된 노래를 두 개씩 모아 베스트 앨범을 출시하려 합니다. 노래는 고유 번호로 구분하며, 노래를 수록하는 기준은 다음과 같습니다. 속한 노래가 programmers.co.kr 문제 해결 방법 해시 맵과 정렬을 사용했다. import java.util.*; class Solution { ArrayList playlist; ArrayList bestalbum; HashMap genremap; HashMap albummap; class Song implements Comparable{ int id; String genre;..

문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/84021 코딩테스트 연습 - 3주차_퍼즐 조각 채우기 [[1,1,0,0,1,0],[0,0,1,0,1,0],[0,1,1,0,0,1],[1,1,0,1,1,1],[1,0,0,0,1,0],[0,1,1,1,0,0]] [[1,0,0,1,1,0],[1,0,1,0,1,0],[0,1,1,0,1,1],[0,0,1,0,0,0],[1,1,0,1,1,0],[0,1,0,0,0,0]] 14 [[0,0,0],[1,1,0],[1,1,1]] [[1,1,1],[1,0,0],[0,0,0]] 0 programmers.co.kr 문제 해결 방법 새로운 newBoard와 newTable을 만든다. 도형이 들어갈 칸은 그 크기의 수로 초기화..
문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/42628 코딩테스트 연습 - 이중우선순위큐 programmers.co.kr 문제 해결 방법 priority queue를 사용하여 구현했다. import java.util.*; class Solution { public int[] solution(String[] operations) { int[] answer = new int[2]; PriorityQueue pq = new PriorityQueue(); for(String s : operations) { String[] op = s.split(" "); if(op[0].equals("I")) { pq.add(Integer.parseInt(op[1])..
문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/43162 코딩테스트 연습 - 네트워크 네트워크란 컴퓨터 상호 간에 정보를 교환할 수 있도록 연결된 형태를 의미합니다. 예를 들어, 컴퓨터 A와 컴퓨터 B가 직접적으로 연결되어있고, 컴퓨터 B와 컴퓨터 C가 직접적으로 연결되어 있 programmers.co.kr 문제 해결 방법 dfs로 구현했다. class Solution { public int solution(int n, int[][] computers) { boolean[] chk = new boolean[n]; int answer = 0; for(int i = 0; i < n; i++) { if(!chk[i]) { dfs(computers, c..
문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/62048 코딩테스트 연습 - 멀쩡한 사각형 가로 길이가 Wcm, 세로 길이가 Hcm인 직사각형 종이가 있습니다. 종이에는 가로, 세로 방향과 평행하게 격자 형태로 선이 그어져 있으며, 모든 격자칸은 1cm x 1cm 크기입니다. 이 종이를 격자 선을 programmers.co.kr 문제 해결 방법 패턴을 구해 수식으로 해결할 수 있는 문제였다. class Solution { public long solution(int w,int h) { long answer = 0; for(int i = 0; i < w; i++) answer += (Long.valueOf(h) * i) / Long.valueOf(..
문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/1844 코딩테스트 연습 - 게임 맵 최단거리 [[1,0,1,1,1],[1,0,1,0,1],[1,0,1,1,1],[1,1,1,0,1],[0,0,0,0,1]] 11 [[1,0,1,1,1],[1,0,1,0,1],[1,0,1,1,1],[1,1,1,0,0],[0,0,0,0,1]] -1 programmers.co.kr 문제 해결 방법 bfs! import java.util.*; class Solution { class Node { int x; int y; int cnt; public Node(int x, int y, int cnt) { this.x = x; this.y = y; this.cnt = cnt; }..
문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/83201 코딩테스트 연습 - 2주차_상호평가 [[100,90,98,88,65],[50,45,99,85,77],[47,88,95,80,67],[61,57,100,80,65],[24,90,94,75,65]] "FBABD" [[70,49,90],[68,50,38],[73,31,100]] "CFD" programmers.co.kr 문제 해결 방법 scores 배열의 열이 해당 index의 학생이 받은 점수이므로 열을 탐색하도록 구현했다. class Solution { public String solution(int[][] scores) { String answer = ""; for(int i = 0; i ..
문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/64062 코딩테스트 연습 - 징검다리 건너기 [2, 4, 5, 3, 2, 1, 4, 2, 5, 1] 3 3 programmers.co.kr 문제 해결 방법 이진 탐색으로 최대 몇 명이 건널 수 있는지 검사한다. mid값 수 만큼의 니니즈 친구들이 징검다리를 건넜을 때 더 이상 밟을 수 없는 돌의 개수가 k 개라면 실패. -> max 값을 줄여준다. k개 미만이라면 성공. -> min 값을 늘려준다. class Solution { public int solution(int[] stones, int k) { int answer = 0; int min = 1; int max = 200000000; whi..