Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 어떤 문제를 풀었나요?
🔑 풀이 접근 방식
처음 시도한 방식(N^2) -> 배열 최대 길이가 100만개라 시간 초과 가능성
stack 단원이 아니라면 힌트를 얻기 어려웠을 것 같긴 하지만
다른 배열을 하나 만들고, j, j+1을 비교하고 다르면 j를 다른 배열에 넣어둠
넣은 이후에 그 배열에서도 다시 검사
근데 코드 짜보니 이 방법도 배열 2개 만들어서 이중 반복 돌려야됨
stack을 만들고 원본 배열의 [0]를 stack에 넣어둠
stack.pop이랑 s[0]이랑 같지 않으면 stack.push(s[0])
stack.pop이랑 s[0]이랑 같으면 stack.pop, s.splice(0,1);
❓ 고민한 점 & 리뷰 요청 사항
💡 어떤 문제를 풀었나요?
🔑 풀이 접근 방식
왜 1초 이후에 가격이 떨어지는것도 1이고 1초 이후에 가격이 오르는 것도 1이냐 -> 바로 떨어져도 그 직전까지 돈을 유지한 것으로 취급해서 최소 유지 기간은 1
그럼 맨 마지막은 0 고정이고 뒤에서부터 순회
-2 위치도 1로 고정(-1이 더 커서 +1을 해도 1이고 작아도 1임)
이후에 뒤에가 더 크면 +1, 아니면 1로 set
흠 근데 거꾸로 순회하면서 return에 넣을 배열 만드는건 앞에 추가해야하는데 이러면 추가할 때마다 N이니까 N^2 될 것 같은데.. 일단 구현해보기
=>
값을 전역으로 유지하면 올랐다 내려가는 상황을 대응할 수 없네
N번씩 순회하면서 새로운 배열에 +1씩 해주는 방식으로 하면 N^2으로는 가능할 것 같은데 배열 크기가 10만이라 안 될 것 같음
❓ 고민한 점 & 리뷰 요청 사항
💡 어떤 문제를 풀었나요?
🔑 풀이 접근 방식
가로줄로 나와있으니 세로줄로 stack을 만들어서 moves의 항목마다 인덱스로 접근해서 pop 할 수 있으면 편하겠지만
이건 사람이 이해하기 편하게 만들려고 한거고 실제로는 굳이 새 stack 만들지 않고 board에서 직접 인덱스 접근해서 0으로 바꿔도 되지 않을까 생각했는데
0이 안 나올 때까지 조회하고 업데이트 하는 과정이 더 비쌀 것 같아서 그냥 세로줄 stack 만드는거로
가로줄로 나와있으니 세로줄로 stack을 만들어서 moves의 항목마다 인덱스로 접근해서 pop 할 수 있으면 편하겠지만
이건 사람이 이해하기 편하게 만들려고 한거고 실제로는 굳이 새 stack 만들지 않고 board에서 직접 인덱스 접근해서 0으로 바꿔도 되지 않을까 생각했는데
0이 안 나올 때까지 조회하고 업데이트 하는 과정이 더 비쌀 것 같아서 그냥 세로줄 stack 만드는거로
❓ 고민한 점 & 리뷰 요청 사항