전체 글
-
Level2) 다리를 지나는 트럭PS/programmers 2020. 10. 11. 15:57
import java.util.*; public class Solution { public int solution(int bridge_length, int weight, int[] truck_weights) { int time = 0; Queue boarding = new LinkedList(); Queue waiting = new LinkedList(); for (int t : truck_weights) { waiting.offer(new Truck(t, bridge_length)); } int remain_weight = weight; while (!(waiting.isEmpty() && boarding.isEmpty())) { if (!waiting.isEmpty()) { int nowWeight ..
-
Level2) 주식가격PS/programmers 2020. 10. 9. 21:45
class Solution { public int[] solution(int[] prices) { int[] answer = new int[prices.length]; for (int i = 0; i prices[j]){ answer[i] = j-i; break; } if(j==prices.length-1){ answer[i] = j-i; } } } return answer; } } - 다시 보니까 옛날에 푼거였던게 어이없음 스택/큐 문제라는데 그렇게 생각하는게 너무 복잡하고 더 어려운거같아서 for문으로 풀이
-
Level2) 프린터PS/programmers 2020. 10. 9. 18:20
import java.util.LinkedList; import java.util.Queue; class Solution { public int solution(int[] priorities, int location) { int answer = 0; Queue q = new LinkedList(); for (int i = 0; i < priorities.length; i++) { q.offer(new Printer(i, priorities[i])); } while (!q.isEmpty()) { boolean flag = false; int com = q.peek().prior; // 맨 앞 for (Printer p : q) { if (com < p.prior) { flag = true; } } if (..
-
Level1) 두 개 뽑아서 더하기PS/programmers 2020. 10. 8. 16:39
import java.util.*; class Solution { public ArrayList solution(int[] numbers) { ArrayList list = new ArrayList(); int leng = numbers.length; for (int i = 0; i < leng; i++) { for (int j = i+1; j < leng; j++) { list.add(numbers[i] + numbers[j]); } } HashSet result = new HashSet(list); list = new ArrayList(result); Collections.sort(list); return list; } } (1) 나의 풀이 1. list에 추가 2. HashSet 생성자에 list를..
-
boj)1748 - 수 이어쓰기 1PS/boj 2020. 9. 22. 17:32
import java.io.*; public class boj_1748 { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { String n = br.readLine(); int N = Integer.parseInt(n); int ans = 0; for (int i = 1; i
-
boj)6064 - 카잉 달력PS/boj 2020. 9. 22. 16:33
import java.io.*; import java.util.StringTokenizer; public class boj_6064 { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; public static void main(String[] args) throws IOException { int t = Integer.parseInt(br.readLine()); for (int i = 0; i < t; i++) { st = new StringTokenizer(br.readLine()); int m = Integer.parseInt(st.nextToken()); ..
-
boj)14500 - 테트로미노PS/boj 2020. 9. 22. 12:00
import java.io.*; import java.util.StringTokenizer; public class boj_14500 { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static int[][] a; public static void main(String[] args) throws IOException { st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); a = new in..
-
boj)1107 - 리모컨PS/boj 2020. 9. 22. 01:50
import java.util.*; public class boj_1107 { static boolean[] broken = new boolean[10]; static int possible(int c) { if (c == 0) { if (broken[0]) { return 0; } else { return 1; } } int len = 0; while (c > 0) { if (broken[c % 10]) { return 0; } len += 1; c /= 10; } return len; } public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt()..