2020.07.29

const solution = (heights) => {
  const stack = [];
  const result = [];
  const limit = heights.length;
  while (stack.length < limit) {
    const popped = heights.pop();
    stack.push(popped);
    let i;
    for (i = heights.length - 1; i >= 0; i--) {
      if (heights[i] > popped) {
        result.unshift(i + 1);
        break;
      }
    }
    if (i < 0) {
      result.unshift(0);
    }
  }
  return result;
};
  • 와 이걸 함수형으로 푸는 사람이 있네...

0개의 댓글