PS/programmers
-
Level2) 기능개발PS/programmers 2020. 11. 10. 13:21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 import java.util.*; class Solution { public int[] solution(int[] progresses, int[] speeds) { Queue q = new LinkedList(); List list = new ArrayList(); int length = progresses.length; for (int i = 0; i
-
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를..