programmers 큰 수 만들기
분류 / 레벨 / 언어
탐욕법(Greedy) / LV.2 / Javscript
설명
처음에는 자료구조를 따로 두지 않고,
input으로 들어온 number만 가지고 풀었다.
그러니 필요이상으로 루프를 돌게되어 시간복잡도가 매우 커졌다.
그래서 정답으로 return할 스택 answer을 하나 추가하고,
k가 남아있을 동안, ‘pop() 이벤트 = k 차감’으로 풀었다
전체 코드
1 | function solution(number, k) { |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
