ํ๋ก๊ทธ๋๋จธ์ค ์ฝ๋ฉํ ์คํธ kit ์คํ/ํ๋ก ๋ถ๋ฅ๋์ด ์๋ ํ, ๋ค๋ฆฌ๋ฅผ ์ง๋๋ ํธ๋ญ, ๊ธฐ๋ฅ๊ฐ๋ฐ, ํ๋ฆฐํฐ, ์ ๋ง๋๊ธฐ, ์ฃผ์๊ฐ๊ฒฉ ๋ฌธ์ ํ์ด.
1.ํ
function solution(heights) {
const answer = [0];
for (let i = 1; i < heights.length; i++) {
for (let j = i - 1; 0 <= j; j--) {
if (heights[j] > heights[i]) {
answer.push(j + 1)
break
}
}
if (answer.length === i) {
answer.push(0)
}
}
return answer;
}
2.๋ค๋ฆฌ๋ฅผ ์ง๋๋ ํธ๋ญ
function solution(bridgeLength, weight, truckWeights) {
truckWeights.reverse()
const onBridge = new Array(bridgeLength).fill(0)
let clock = 1
let curr = truckWeights.pop()
let onWeight = curr
onBridge[0] = curr
while (onWeight) {
onWeight -= onBridge.pop();
curr = truckWeights.pop()
if (onWeight + curr <= weight) {
onBridge.unshift(curr)
onWeight += curr
} else {
onBridge.unshift(0)
truckWeights.push(curr)
}
clock++
}
return clock
}
3.๊ธฐ๋ฅ๊ฐ๋ฐ
function solution(progresses, speeds) {
const days = progresses.map((x, i) => Math.ceil((100 - x) / speeds[i]))
const answer = [1]
let prev = days[0]
for (let i = 1; i < days.length; i++) {
if (days[i] <= prev) {
answer[answer.length - 1]++
} else {
answer.push(1)
prev = days[i]
}
}
return answer
}
4.ํ๋ฆฐํฐ
function solution(priorities, location) {
const ordered = [...priorities].sort((a, b) => a < b ? 1 : -1)
priorities = priorities.map((x, i) => [x, i])
for (let i = 0; i < ordered.length; i++) {
while (priorities[0][0] !== ordered[i]) {
priorities.push(priorities.shift())
}
const [_, j] = priorities.shift();
if (j === location) {
return i + 1;
}
}
}
5.์ ๋ง๋๊ธฐ
function solution(arrangement) {
let left = 0, answer = 0;
for (let i = 0; i < arrangement.length; i++) {
if (arrangement[i] === ')') {
left--
answer++
} else {
if (arrangement[i+1] === ')') {
answer += left
i++
} else {
left++
}
}
}
return answer
}
6.์ฃผ์๊ฐ๊ฒฉ
def solution(prices):
answer = []
for i in range(len(prices) - 1):
answer.append(0)
for j in range(i + 1, len(prices)):
answer[-1] += 1
if prices[i] > prices[j]:
break
answer.append(0)
return answer