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