From 092d462e0be625e736380dc104df906f662aaa43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=AF=BC=ED=98=9C?= Date: Sun, 27 Oct 2024 16:46:53 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=A3=BC=EC=8B=9D=20=EA=B0=80=EA=B2=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...74\354\213\235\352\260\200\352\262\251.js" | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 "\354\212\244\355\203\235/\354\243\274\354\213\235\352\260\200\352\262\251.js" diff --git "a/\354\212\244\355\203\235/\354\243\274\354\213\235\352\260\200\352\262\251.js" "b/\354\212\244\355\203\235/\354\243\274\354\213\235\352\260\200\352\262\251.js" new file mode 100644 index 0000000..95c84df --- /dev/null +++ "b/\354\212\244\355\203\235/\354\243\274\354\213\235\352\260\200\352\262\251.js" @@ -0,0 +1,64 @@ +// O(N^2) 풀이 +function solution(prices) { + // 1. 반복을 돌면서 스택의 마지막 값이 현재 넣을 값보다 크거나 같은 경우에만 집어넣는다. + // 1-1. 현재 인덱스의 하위 인덱스의 카운트를 모두 증가시킨다. + // 2. 만약 현재 넣을 값이 더 작은 값이면 마지막 원소보다 크거나 같은 값이 될 때까지 pop을 하여 원소를 빼낸다. + const stack = []; + const answer = []; + + prices.forEach((price, index) => { + answer.push(prices.length - 1 - index); + }); + + const logs = []; + + for(let i = 0; i 0) { + const j = stack.pop(); + answer[j] = prices.length - 1 - j; + } + + return answer; +} \ No newline at end of file