題目
思路:
因為要做一個 linked list,可以用 while 在每次迴圈都接一個 node 出來
先設
while True:,等寫迴圈內容時再來確定 while 可繼續執行的條件寫第一 part (如下) 後發現,while 條件需要
l1 and l21
2
3
4
5
6if l1.val > l2.val:
curr.next = l2
l2 = l2.next
else:
curr.next = l1
l1 = l1.next
題目
思路:
因為要做一個 linked list,可以用 while 在每次迴圈都接一個 node 出來
先設 while True:,等寫迴圈內容時再來確定 while 可繼續執行的條件
寫第一 part (如下) 後發現,while 條件需要 l1 and l2
1 | if l1.val > l2.val: |
題目
思路:
既然是 Linked List,我們可以宣告一個指標 curr 指向第一個 node,用 while 迴圈一次檢查一個 node (檢查完將指標移到下一個 node)
head 來移動,因為到時候回傳答案的時候需要回傳這個 head設定 while 可以繼續檢查的條件:有時要先寫 while 的內容,才會比較確定 while 條件應該怎麼寫,這時可以先寫 while True:,等內容寫完再來改條件
題目
思路:
題目
思路:最直覺是直接 iterate nums,不過題目指定要 O(log n),所以用 binary search 才能達到
設定左右兩個指標作為可能答案範圍:[left, right],目標是移動這兩個指標,縮小答案範圍,直到我們找到答案或答案範圍縮到只剩 1 個為止
while left < right: binary search 什麼時候需要繼續下去?只要符合這個條件,就繼續 binary search
如果去 google,大部分查到的都會說因為 Python 會把 key 經過 hash function 運算,得到一個 dict 真正內部在使用的 key,從而找到對應的 value。而一個好的 hash function 它的運算所需時間是不會隨著 n 增加而變大的,所以 dict 的 get item operation 時間複雜度為 O(1) 。
不過我的疑惑是,經過 hash function 運算得到 key 之後,由這個 key 去找到 value 的時間複雜度是 O(1) 嗎?除非這個也是 O(1) 才能說整個 get item operation 是 O(1) 。
ssh-keygen -t ed25519 -C "{你的 email}"
id_ed25519 自行替換成自己的檔名vi ~/.ssh/config
舉例:加上如下
1 | Host GitHub |
ssh-add -K ~/.ssh/id_ed25519
ssh-agentpbcopy < ~/.ssh/id_ed25519.pub
貼到所使用的服務網站的相對應設定頁面
container run 起來之後:
PostgreSQL:
docker exec -it {db-container-name} psql -U postgrespostgres 連進 DBcreate user {username} with password '{password}';create database {database_name} with owner {username};
Update your browser to view this website correctly. Update my browser now