# fakeNode概念 原本的node結構宣告 ```python= # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next ``` 如下圖,這沒有任何意義,他只是給你一個初始值-1 也可以給0 ```python= cur = ListNode(-1) # fake node ``` 所以我們在使用串linked list 就要從下一個開始node 開始才是有用的node 如下 ```python= return cur.next ``` 所以,當然,我們也要miantain 一個variable 去儲存原本的位置, 然後 讓head 去跑 不然你只有一個 跑一跑 你就找不到首節點在哪裡了 ```python= head =cur ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up