728x90
연결리스트를 끝까지 순회하는 방법
LeetCode 같은 경우
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
def traverse(self):
if self.head == None:
return []
curr = self.head
res = []
while curr:
res.append(curr.data)
curr = curr.next
return res
728x90
'DC 2' 카테고리의 다른 글
[자료구조] 스택 파이썬(LeetCode, Programmers) (0) | 2021.04.20 |
---|---|
[자료구조] Doubly Linked List 구현 (0) | 2021.04.20 |
[자료구조] Linked List 클래스 구현 (0) | 2021.04.20 |
[자료구조] 이진탐색 (Binary Search) 파이썬 (bisect, recursion, iteration) (0) | 2021.04.20 |
[자료구조] 재귀함수 파이썬 (recursive, iterative, decorator, reduce) (0) | 2021.04.20 |
댓글