class Solution: def doubleIt(self, head: Optional[ListNode]) -> Optional[ListNode]: up = False order = [] cur = head while cur.next != None: order.append(cur) cur = cur.next order.append(cur) while order: cur = order.pop() if cur.val * 2 >= 10: cal = up up = True cur.val = (cur.val * 2 + cal) % 10 else: cal = up up = False cur.val = cur.val * 2 + cal if up == True: new_head = ListNode(val=1, next=head) return new_head return head무난하게...리스트 안 쓰고 메모리 절약하는 방법도 있겠지만.. 귀찮아..
댓글 영역
획득법
① NFT 발행
작성한 게시물을 NFT로 발행하면 일주일 동안 사용할 수 있습니다. (최초 1회)
② NFT 구매
다른 이용자의 NFT를 구매하면 한 달 동안 사용할 수 있습니다. (구매 시마다 갱신)
사용법
디시콘에서지갑연결시 바로 사용 가능합니다.