[프로그래머스/Lv.2] PCCP - 석유 시추 (Java)
·
✏️/Programmers
석유 시추https://school.programmers.co.kr/learn/courses/30/lessons/250136풀이덩어리 찾기0: 빈 칸 / 1: 아직 처리 X 석유 / 2부터 덩어리 번호 사용HM에 덩어리 번호와 크기 저장Map HM = new HashMap();int id = 2;for (int i = 0; i BFS(r, c)에서 시작하는 석유 덩어리 크기 계산`land[r][c] = id`: `land`에 `id`(덩어리 번호) 기록public int bfs(int r, int c, int id) { Queue q = new ArrayDeque(); q.offer(new int[]{r, c}); visited[r][c] = true; land[r][c] = id..
[프로그래머스/Lv.2] PCCP - 퍼즐 게임 챌린지 (Java)
·
✏️/Programmers
퍼즐 게임 챌린지https://school.programmers.co.kr/learn/courses/30/lessons/340212풀이숙련도(`level`)의 최솟값 + 단조 감소(`level` ↑ -> `total` ↓) => 이분 탐색 1 모든 퍼즐의 난이도 >= 최댓값 -> 절대 실패 X-> 가능한 `level` 범위: 1 =>`lt = 1`, `rt = 100,000` 실패 X -> 1번만실패 O 실패 횟수: `diffs[i] - mid`각 실패마다 `time+cur + time_prev`/ 마지막 성공 시 `time_cur`if (diffs[i] 코드class Solution { public int solution(int[] diffs, int[] times, long limit) { ..
[프로그래머스/Lv.1] 개인정보 수집 유효기간 (Java)
·
✏️/Programmers
개인정보 수집 유효기간https://school.programmers.co.kr/learn/courses/30/lessons/150370풀이한 달 = 28일 -> 모든 날짜를 일(day)로 변환해서 계산static int convert(String date) { String[] d = date.split("\\."); int y = Integer.parseInt(d[0]); int m = Integer.parseInt(d[1]); int day = Integer.parseInt(d[2]); return y * 12 * 28 + m * 28 + day;} `terms`를 `HashMap`에 저장Map HM = new HashMap();for (String t : terms) { ..
[프로그래머스/Lv.1] 성격 유형 검사하기 (Java)
·
✏️/Programmers
성격 유형 검사하기https://school.programmers.co.kr/learn/courses/30/lessons/118666풀이`survey` + `score``choice`: 1 -> 앞 문자 +3`choice`: 2 -> 앞 문자 +2`choice`: 3 -> 앞 문자 +1`choice`: 4 -> 0`choice`: 5 -> 뒤 문자 +1`choice`: 6 -> 뒤 문자 +2`choice`: 7 -> 뒤 문자 +3ex. survey = "AN" / choice = 2 -> 앞 문자(R) +2점for (int i = 0; i 코드import java.util.*;class Solution { public String solution(String[] survey, int[] choice..
[프로그래머스/Lv.1] 비밀지도 (Java)
·
✏️/Programmers
비밀지도https://school.programmers.co.kr/learn/courses/30/lessons/17681풀이`map = arr1[i] | arr2[i]`: 둘 중 하나라도 1이면 1-> ex. arr1[i] = 9(10진수) = 1001(2진수) 컴퓨터 안에서는 항상 이진수로 저장 `Integer.toBinaryString(map)`으로 이진수 변환하면 앞의 0 자동으로 빠짐-> `String.format("%" + n + "s", binary)`로 공백 채우기(길이가 n이 될 때까지 왼쪽에 공백 채워서 문자열 맞추기) 1 -> '#' / 0 -> ' '로 벽 변환코드class Solution { public String[] solution(int n, int[] arr1, int[..
[프로그래머스/Lv.1] 크레인 인형뽑기 (Java)
·
✏️/Programmers
크레인 인형뽑기https://school.programmers.co.kr/learn/courses/30/lessons/64061풀이해당 열에서 위에서부터 인형 찾기`moves`: 크레인이 이동하는 열 번호`col = m - 1` => 0-based 인덱스로 변환 `board[row][col] != 0`: 인형 발견 `borad[row][col] = 0`: 인형 뽑기바구니 맨 위 인형같음 -> 2개 사라짐: `stack.poll()`, `cnt += 2`다름 -> `stack.push(doll)`예시board = [[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]] col: 1 2 3 4 5-------------------row0 | 0 ..
aeongg
'✏️/Programmers' 카테고리의 글 목록