[筆記] Master The Coding Interview – 6

這篇是 Udemy 上的知名課程 – Master the Coding Interview 的部分進修心得。這篇對應的內容是「Data Structures: Hash Tables」關於陣列的第二部分簡介。
coding interview


課程相關資訊

[連結]:https://www.udemy.com/course/master-the-coding-interview-data-structures-algorithms/

課程對應章節:80~86

請注意:本系列文章為個人對應課程的消化吸收後,所整理出來的內容。換言之,並不一定會包含全部的課程內容,也有可能會添加其他資源來說明。


內容

背景知識

1. 承接上篇,若要取得 keys() 的列表陣列,可以寫迴圈遍歷即可,其複雜度為 O(n)
2. 為何有些場合要使用 Hash Tables 而不是 Array?因為 Hash Tables 在空間足夠的狀態下(避免 Collision 衝突情形),其 search, insert, lookup 和 delete 的時間複雜度都為 O(1)。Array 的話,若要查詢、新增和刪除,複雜度都為 O(n)。
3. First Recurring Character:
思路 I :用雙重迴圈,分別讓陣列中的數字兩兩對比。若有重複就回傳。(但要小心陣列的比較順序)
思路 II :用 Hash Table,把數字當作 key ,value 則存 true。如此一來,當 map[key] 存在的時候,因為其 value 為 true,則 return 當下的數字。


範例程式碼


相關文章

★全文分享★  [筆記] Master The Coding Interview – 16
[筆記] Master The Coding Interview – 16
這篇是 Udemy 上的知名課程 – Master the Coding Interview 的部分進修心得。這篇對應的內容是「Data Structures: Tree」關於樹的第四部分簡介。課程相關資訊[連結]:https://www.udemy.com/course/master-the-coding-interview-d
★全文分享★  [筆記] Master The Coding Interview – 15
[筆記] Master The Coding Interview – 15
這篇是 Udemy 上的知名課程 – Master the Coding Interview 的部分進修心得。這篇對應的內容是「Data Structures: Tree」關於樹的第三部分簡介。課程相關資訊[連結]:https://www.udemy.com/course/master-the-coding-interview-d
★全文分享★  [筆記] Master The Coding Interview – 14
[筆記] Master The Coding Interview – 14
這篇是 Udemy 上的知名課程 – Master the Coding Interview 的部分進修心得。這篇對應的內容是「Data Structures: Tree」關於樹的第二部分簡介。課程相關資訊[連結]:https://www.udemy.com/course/master-the-coding-interview-d
★全文分享★  [筆記] Master The Coding Interview – 13
[筆記] Master The Coding Interview – 13
這篇是 Udemy 上的知名課程 – Master the Coding Interview 的部分進修心得。這篇對應的內容是「Data Structures: Tree」關於樹的第一部分簡介。課程相關資訊[連結]:https://www.udemy.com/course/master-the-coding-interview-d
★全文分享★  [筆記] Master The Coding Interview – 12
[筆記] Master The Coding Interview – 12
這篇是 Udemy 上的知名課程 – Master the Coding Interview 的部分進修心得。這篇對應的內容是「Data Structures: Stacks + Queues」關於堆疊和序列的第三部分簡介。課程相關資訊[連結]:https://www.udemy.com/course/master
★全文分享★  [筆記] Master The Coding Interview – 11
[筆記] Master The Coding Interview – 11
這篇是 Udemy 上的知名課程 – Master the Coding Interview 的部分進修心得。這篇對應的內容是「Data Structures: Stacks + Queues」關於堆疊和序列的第二部分簡介。課程相關資訊[連結]:https://www.udemy.com/course/master
★全文分享★  [筆記] Master The Coding Interview – 10
[筆記] Master The Coding Interview – 10
這篇是 Udemy 上的知名課程 – Master the Coding Interview 的部分進修心得。這篇對應的內容是「Data Structures: Stacks + Queues」關於堆疊和序列的第一部分簡介。課程相關資訊[連結]:https://www.udemy.com/course/master
★全文分享★  [筆記] Master The Coding Interview – 9
[筆記] Master The Coding Interview – 9
這篇是 Udemy 上的知名課程 – Master the Coding Interview 的部分進修心得。這篇對應的內容是「Data Structures: Linked Lists」關於鏈結陣列的第三部分簡介。課程相關資訊[連結]:https://www.udemy.com/course/master-the-c
★全文分享★  [筆記] Master The Coding Interview – 8
[筆記] Master The Coding Interview – 8
這篇是 Udemy 上的知名課程 – Master the Coding Interview 的部分進修心得。這篇對應的內容是「Data Structures: Linked Lists」關於鏈結陣列的第二部分簡介。課程相關資訊[連結]:https://www.udemy.com/course/master-the-c
★全文分享★  [筆記] Master The Coding Interview – 7
[筆記] Master The Coding Interview – 7
這篇是 Udemy 上的知名課程 – Master the Coding Interview 的部分進修心得。這篇對應的內容是「Data Structures: Linked Lists」關於鏈結陣列的第一部分簡介。課程相關資訊[連結]:https://www.udemy.com/course/master-the-c
★全文分享★  [筆記] Master The Coding Interview – 5
[筆記] Master The Coding Interview – 5
這篇是 Udemy 上的知名課程 – Master the Coding Interview 的部分進修心得。這篇對應的內容是「Data Structures: Hash Tables」關於陣列的第一部分簡介。課程相關資訊[連結]:https://www.udemy.com/course/master-the-coding-i
★全文分享★  [筆記] Master The Coding Interview – 4
[筆記] Master The Coding Interview – 4
這篇是 Udemy 上的知名課程 – Master the Coding Interview 的部分進修心得。這篇對應的內容是「Data Structures: Array」關於陣列的第二部分簡介。課程相關資訊[連結]:https://www.udemy.com/course/master-the-coding-intervi
★全文分享★  [筆記] Master The Coding Interview – 3
[筆記] Master The Coding Interview – 3
這篇是 Udemy 上的知名課程 – Master the Coding Interview 的部分進修心得。這篇對應的內容是「Data Structures: Array」關於陣列的簡介。課程相關資訊[連結]:https://www.udemy.com/course/master-the-coding-interview-data-stru
★全文分享★  [筆記] Master The Coding Interview – 2
[筆記] Master The Coding Interview – 2
這篇是 Udemy 上的知名課程 – Master the Coding Interview 的部分進修心得。這篇對應的內容是「Data Structure」資料結構的簡介。課程相關資訊[連結]:https://www.udemy.com/course/master-the-coding-interview-data-structures-a
★全文分享★  [筆記] Master The Coding Interview – 1
[筆記] Master The Coding Interview – 1
工程師的面試中,不免俗的會遇見用各種型式來考你的演算法功力。這篇是 Udemy 上的知名課程 – Master the Coding Interview 的進修心得。目標是在這兩邊的精進後,可以自在的解決 LeetCode 上的問題。課
按讚加入粉絲團

延伸閱讀