물음표 살인마의 개발블로그

알고리즘 문제/Leetcode

1265. Print Immutable Linked List in Reverse

BEstyle 2023. 4. 11. 15:03
# """
# This is the ImmutableListNode's API interface.
# You should not implement it, or speculate about its implementation.
# """
# class ImmutableListNode:
#     def printValue(self) -> None: # print the value of this node.
#     def getNext(self) -> 'ImmutableListNode': # return the next node.

class Solution:
    def printLinkedListInReverse(self, head: 'ImmutableListNode') -> None:
        ans=[]
        while head:
            ans.append(head)
            head=head.getNext()
        for h in ans[::-1]:
            h.printValue()

'알고리즘 문제 > Leetcode' 카테고리의 다른 글

1302. Deepest Leaves Sum  (0) 2023.04.11
1570. Dot Product of Two Sparse Vectors  (0) 2023.04.11
209. Minimum Size Subarray Sum  (0) 2023.04.04
229. Majority Element II  (0) 2023.04.04
287. Find the Duplicate Number  (0) 2023.04.04