class Solution:
def removeNodes(self, head: Optional[ListNode]) -> Optional[ListNode]:
first = []
cur = head
while cur.next != None:
first.append(cur)
cur = cur.next
second = [cur]
mx = cur.val
while first:
cur = first.pop()
if cur.val >= mx:
second.append(cur)
mx = cur.val
second = second[::-1]
for i in range(len(second)-1):
second[i].next = second[i+1]
return second[0]
릿코드는 링크드리스트 문제 왤케 좋아하는지 모르겠다.
가장 간단한 구조인데... 이거 못 푸는 놈들 거르기 용인가
댓글 0