https://programmers.co.kr/learn/courses/30/lessons/42588
함수형으로 풀기
function findReceivedTop(acc, currentValue, currentIndex, array){
if(currentIndex === 0){
return [0]
}
for(let i=currentIndex-1; i >= 0;i--){
if( array[i] > currentValue)
{
acc.push(i+1)
return acc
}
}
acc.push(0)
return acc
}
function solution(heights) {
const getReceivedTops = heights.reduce(findReceivedTop,0)
return getReceivedTops;
}
function findReceivedTop(acc, currentValue, currentIndex, array){
if(currentIndex === 0){
return [0]
}
for(let i=currentIndex-1; i >= 0;i--){
if( array[i] > currentValue)
{
acc.push(i+1)
return acc
}
}
acc.push(0)
return acc
}
function solution(heights) {
const getReceivedTops = heights.reduce(findReceivedTop,0)
return getReceivedTops;
}
'Computer Science > 알고리즘 ( Algorithm )' 카테고리의 다른 글
python 2d array 회전 (0) | 2020.02.23 |
---|---|
피보나치 수열 - 황금비율 문제 (0) | 2020.02.22 |
K번째 수 (0) | 2019.10.06 |
XX 알고리즘 문제 7 (0) | 2019.04.28 |
XX 알고리즘 문제 6 (0) | 2019.04.28 |