From addf9e4e697744de60f2f8af5554c733bc295271 Mon Sep 17 00:00:00 2001 From: sujunghwang <64738942+sujunghwang@users.noreply.github.com> Date: Thu, 23 Feb 2023 09:45:08 +0900 Subject: [PATCH] =?UTF-8?q?Week05=20PRG=2042584=20=EC=A3=BC=EC=8B=9D?= =?UTF-8?q?=EA=B0=80=EA=B2=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sujunghwang/week05/PRG_42584.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 sujunghwang/week05/PRG_42584.java diff --git a/sujunghwang/week05/PRG_42584.java b/sujunghwang/week05/PRG_42584.java new file mode 100644 index 0000000..6592743 --- /dev/null +++ b/sujunghwang/week05/PRG_42584.java @@ -0,0 +1,27 @@ +/* +https://school.programmers.co.kr/learn/courses/30/lessons/42584?language=java + +주어진 배열을 탐색하면서 현재 값보다 작은 값이 언제 나오는지 구하면 되는 문제 +문제 카테고리는 스택/큐 였는데 모르겠어서 그냥 배열로 이중 for loop 돌림 +효율성 문제 생길 줄 알았는데 안생겨서 그냥 넘어가기로 함 +*/ + +class Solution { + public int[] solution(int[] prices) { + int len = prices.length; + int[] answer = new int[len]; + + for(int i = 0; i < len-1; i++){ + answer[i] = 1; + for(int j = i+1; j < len-1; j++){ + if(prices[j] >= prices[i]){ + answer[i] += 1; + } else { + break; + } + } + } + + return answer; + } +}