목록코테/프로그래머스 (33)
공부기록
문제 https://programmers.co.kr/learn/courses/30/lessons/49191 코드 import java.util.*; class Solution { int bfs(ArrayList g[], int s_idx){ Queue q = new LinkedList(); boolean visit[] = new boolean[g.length]; int count = 0; q.add(s_idx); visit[s_idx] = true; while(!q.isEmpty()){ count++; int cur_idx = q.poll(); for(int next_idx : g[cur_idx]){ if(visit[next_idx] == false){ q.add(next_idx); visit[next_..
문제 https://programmers.co.kr/learn/courses/30/lessons/43238# 코드 import java.util.*; class Solution { private int is_prom(int n, long mid, int[] times){ long left_man = n; for(int time : times){ left_man -= (mid/time); } // System.out.println("n : " + n + ", left_man : " + left_man); if(left_man > 0) return -1; else return 0; } public long solution(int n, int[] times) { long answer = 0; long low ..
문제 https://programmers.co.kr/learn/courses/30/lessons/42884 코드 import java.util.*; class Solution { class Node implements Comparable{ int s; int e; public Node(int s, int e){ this.s = s; this.e = e; } public int compareTo(Node obj){ if(this.s obj.s) return 1; else return 0; } } public int solution(int[][] routes) { int answer = 0; PriorityQueue pq = new Prior..
문제 https://programmers.co.kr/learn/courses/30/lessons/42861 코드 import java.util.*; class Solution{ class Node implements Comparable{ int e; int w; public Node(int e, int w){ this.e = e; this.w = w; } @Override public int compareTo(Node obj){ if(this.w > obj.w) return 1; else if(this.w < obj.w) return -1; else return 0; } } public int solution(int n, int[][] costs) { int answer = 0; ArrayList g[]..
문제 https://programmers.co.kr/learn/courses/30/lessons/43164# 코드 import java.util.*; class Solution { void dfs(String[][] tickets, HashMap map, HashMap tckt_count, ArrayList res, ArrayList cur_arr, String cur_pos, int count){ if(count == tickets.length){ ArrayList res_arr = new ArrayList(); for(int i=0; i
문제 https://programmers.co.kr/learn/courses/30/lessons/42628# 코드 import java.util.*; class Solution { public int[] solution(String[] operations) { int[] answer = {0, 0}; PriorityQueue rpq = new PriorityQueue(); PriorityQueue pq = new PriorityQueue(Collections.reverseOrder()); for(String oper : operations){ String[] oper_arr = oper.split(" "); String cmd = oper_arr[0]; int arg = Integer.valueOf(op..
문제 https://programmers.co.kr/learn/courses/30/lessons/12911 코드 import java.util.*; class Solution { int min_val = 2000000000; int n_val = 0; int count_one(int n){ int cursor = 1; int one_c = 0; while(cursor
문제 https://programmers.co.kr/learn/courses/30/lessons/42883 내 코드 import java.util.*; class Solution { public String solution(String number, int k) { String answer = ""; Stack s = new Stack(); for(int i=0; i 0 && s.peek() 0){ s.pop(); k--; } while(!s.isEmpty()){ answer = s.pop() + answer; } return answer; } } 피드백 결론은 스택을 사용해서 k가 허용되는 한 내리막길을 만드..