林建慶
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # LeetCodeCollections [![hackmd-github-sync-badge](https://hackmd.io/oFGEhcbSS2OSunc6adfa1w/badge)](https://hackmd.io/oFGEhcbSS2OSunc6adfa1w) ![](https://i.imgur.com/AyFYwud.png) ## Introduction This note is my personal Leetcode practice. Trying to articulate them after my learning. At the same time I'd like to practice English writing as well so as these notes would be completed in English. This way it would be easier to review in the future if needed. - [Github](https://github.com/Jaimecclin/LeetCodeCollections) ## Categories ### Tree - Problems 1. Medium [144. Binary Tree Preorder Traversal](https://hackmd.io/zZk01ti-RRWkcDXigm1ayg) 2. Medium [94. Binary Tree Inorder Traversal](https://hackmd.io/ivApRuhVQEyjMYJhHNutBQ) 3. Hard [145. Binary Tree Postorder Traversal](https://hackmd.io/rck1NUdnQp2EmJ9sxQ95jg) 4. Medium [102. Binary Tree Level Order Traversal](https://hackmd.io/0PSEluNbSByMXeedCW2_Jw) 5. Easy [108. Convert Sorted Array to Binary Search Tree](/9yHJ1lqEQ2K_E-BSyRpaSw) 6. Easy [100. Same Tree](https://hackmd.io/jKv-6ydHQW-j6uxzBYLXKQ) 7. Easy [101. Symmetric Tree](https://hackmd.io/h0wlxDL6TtCMphddrEFXMQ) 8. Easy [226. Invert Binary Tree](https://hackmd.io/MOk4wB92Tdy7ERvVzNuL7g) 9. Easy [257. Binary Tree Paths](https://hackmd.io/3w79PJA4Su6YUnwV8Tva2g) 10. Easy & Medium [112. Path Sum I & II](https://hackmd.io/X8BMywz0Q3qV2co8Ooy7jw) 11. Medium [129. Sum Root to Leaf Numbers](https://hackmd.io/xXTzDelzTDG7midQSwoDBw) 12. 298. Binary Tree Longest Consecutive Sequence (Cant write) 13. Easy [111. Minimum Depth of Binary Tree](https://hackmd.io/hP-lAWAISZaoPwt89ZBJug) 14. Easy [104. Maximum Depth of Binary Tree](https://hackmd.io/0CRV6MFJRaGek8BTvlPLDQ) 15. Easy [110. Balanced Binary Tree](https://hackmd.io/V1QgcuVURpaaox5fizZ2Gw) 16. Hard [124. Binary Tree Maximum Path Sum ](https://hackmd.io/Ucst_AvCTTmgTSS-5k7DvQ) 16. [250. Count Univalue Subtrees](https://hackmd.io/zpsx3k4yQ26RrcBjQaGsog) 17. 366. Find Leaves of Binary Tree (Cant write) 18. Medium [337. House Robber III](https://hackmd.io/soSVP8ANQDeCtfR0YG1DQA) 19. Easy [107. Binary Tree Level Order Traversal II](https://hackmd.io/JS9gBNR-SKOAW1_BNg1RGg) 20. Easy [103. Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/) 21. Medium [199. Binary Tree Right Side View](https://hackmd.io/v59LyFAZSS-fiEipiy0yrA) 22. Medium [98. Validate Binary Search Tree](https://hackmd.io/NItMkXJ0Rw68KX2X3HTwyQ) 23. Medium [116. Populating Next Right Pointers in Each Node](https://hackmd.io/rJcvys3sS1W5hq5ojUy7OQ) - Note 1. Three ways of Depth First Search: (1)Preorder (2)Inorder (3)Postorder are very important. 2. (Cont'd) It's better to understand recursive and iterative implementation of DFS. 3. Classic Tree Height ```cpp int getHeight(TreeNode* root) { if(!root) { return 0; } int leftH = getHeight(root->left); int rightH = getHeight(root->right); int maxH = max(leftH, rightH); return maxH + 1; } ``` --- ### Array - Problems 1. Easy [27. Remove Element](https://hackmd.io/JZISslIOQUaq_wj5rlHLTA) 2. Easy [26. Remove Duplicates from Sorted Array](https://hackmd.io/Smz2SJ57QFe_4K0Gqeyzig) 3. Medium 80. [Remove Duplicates from Sorted Array II](https://hackmd.io/ow-3prR1Sc2WNJWJzZ_z5Q) 4. Unknown 277. Find the Celebrity 5. Easy 189. [Rotate Array](https://hackmd.io/yQ0XjBRqQVySVij7RMbM1w) 6. Hard 41. [First Missing Positive](https://hackmd.io/rWIvxsXxQxumb187Zyy4zw) 7. Easy [ 299. Bulls and Cows](https://hackmd.io/CAbJ7lNbT-O-fKjvwGfzFw) 8. Medium 134. [Gas Station](https://hackmd.io/ogUTvf_BQ6uBd0XO7DAYZA) 9. Medium 274.& 275. [H-Index](https://hackmd.io/mRIs13zZQRWBnzX7SkvkvA) 10. Easy & Medium 243. 244. 245 [Shortest Word Distance I, II, III](https://hackmd.io/0YOnPYVGRiO09c7bP1ECJA) 11. Easy [217. Contains Duplicate](https://hackmd.io/3fLIOv39RKeYpRvmJuBCGw) 12. Easy 219. 220. [Contains Duplicate II & III](https://hackmd.io/9Cuqqr16RR6piKthWvdWCg) 13. Medium 55. Hard 45 [Jump Game I & II](https://hackmd.io/KAhEVPc6SemUntgRYOBJrw) (So hard) 14. Hard [121. 188. Best Time to Buy and Sell Stock](https://hackmd.io/huYrV_FbTTqzAtEWM5xnFg) 15. Medium 11. [Container With Most Water](https://hackmd.io/NkSkdiMOSIu3scMctcaqZQ) 16. Hard [42. Trapping Rain Water](/thsXvd_CSMSl-axI1MqWOQ) 17. Medium [334. Increasing Triplet Subsequence](/p9TGRO7FTiaovOWA6Oshsg) 18. Hard [128. Longest Consecutive Sequence](/oAZsQ6EmSLyOlZ-djoatCQ) 19. Hard [164. Maximum Gap](/2NP1IPjTQqSLfFjn2-EMQw) 20. Medium [525. Contiguous Array](/QIe-FVy3QdaNOQy8wDBImQ) 21. Mediun [287. Find the Duplicate Number](/zwNvhxWtSIqP8jHgmBkfUw) 22. Easy [53. Maximum Subarray](/AoXMcftKR5yPFTCLtp5_vQ) - Note 1. Be aware it is a sorted array. 2. Two pointers usually is good way to solve. 3. Be careful of negtive index in Python. 4. You have no precise array imagination. More practice needed. --- ### LinkedList - Problems 1. Easy [206. Reverse Linked List](https://hackmd.io/TzUkBaBlSjuXJ2alR0UhEA) 2. Easy [1290. Convert Binary Number in a Linked List to Integer](/Q-O2MNFmRnC0b6K46OT72g) 3. Easy [876. Middle of the Linked List](/c0B8gOvpSoW1ruksN8n7Aw) 4. Easy [21. Merge Two Sorted Lists](/yoADbDLKQSqLFOCDB0NdHg) 5. Easy [237. Delete Node in a Linked List](https://hackmd.io/6d28t3ARSi-Xgg7xcF4F4A?both) 6. Easy [234. Palindrome Linked List](/O-Re3xflRnaJws3UdeTDcw) 7. Easy [141. Linked List Cycle](https://hackmd.io/dCY2MdBUS56Rc9DAWebn1g) 8. Easy [24. Swap Nodes in Pairs](https://hackmd.io/fGUrk1XYSL-LCzehPQyOaw) 9. Medium [1721. Swapping Nodes in a Linked List](/-ivcojW0RhiEFEiCW-2fsQ) 10. Medium [143. Reorder List](/u2K2S5o7Q-ihYbMVJQbp0w) 11. Medium [148. Sort List](/YkSImjM5SPaqgWEPA_jeLg) 12. Medium [328. Odd Even Linked List](https://hackmd.io/2rqJAKhcSam7fmhvrF7jTw) 13. Medium [142. Linked List Cycle II](/_aTXzrzYQjWkTnOPw4IYjg) 14. Medium [382. Linked List Random Node](/g7RyEQ9xRPmvx8cnQtPWPw) 15. Medium [92. Reverse Linked List II](/sIDEXRSCTBOTMuRtf96MLw) 16. Medium [2. Add Two Numbers](/O57PNKdvT--T3QF3OF10zQ) 17. Medium [445. Add Two Numbers II](/CCq3Pi6USuWRj7o5skZ6Jg) 18. Medium [61. Rotate List](/0Bq1VBgaQw2qbYpoU6Jvbw) 19. Medium [19. Remove Nth Node From End of List](/1q1KxpJNRsCxYoFGYeL96A) 20. Medium [2181. Merge Nodes in Between Zeros](/InokOrGBTiWy1rbtB3QrtA) 21. Medium [114. Flatten Binary Tree to Linked List](/obCpBlQuQ6uh31nFNus3mQ) 22. Easy [83. Remove Duplicates from Sorted List](https://hackmd.io/stOGxq_QT3as5DW3fLq26Q) 23. Easy [203. Remove Linked List Elements](https://hackmd.io/nHVP-6myQF-lAMYWNXmvhw) 24. Medium [Remove Duplicates from Sorted List II](https://hackmd.io/N4KXJWoDTk2d6lptlAnChw) 25. Medium [369 Plus One Linked List](https://hackmd.io/Lk0iSFYfTcSJBc_5Epmzrg) 26. Easy [Intersection of Two Linked Lists](https://hackmd.io/fmK2esz-QYCYYqXV1gNNKQ) 27. Add Two Numbers 28. Merge Two Sorted Lists - Note 1. Adding a dummy node which points to the head might be helpful. 2. The fast and slow pointers helps you find the middle node. The middle one is the end of first list. 3. Tow pointers is the problem killer. --- ### Backtracking - Problems 1. Medium [78. Subsets](https://hackmd.io/oHxTt4-AQLeLzlycvc1GgQ?edit) 2. Medium [90. Subsets II](/GkLo6PsAQ-q2EdpEBP_fgQ) 3. Medium [77. Combinations](/2cmF81g-THCwxQJpo7mxzA) 4. Medium [39. Combination Sum](/xCgk_Q4VTuG9DFVsLM_mOg) 5. Medium [40. Combination Sum II](https://hackmd.io/Lw9_W0IqRpqvrRFsgUnIHA) 6. Medium [216. Combination Sum III](https://hackmd.io/2TSjD5RNThGGvMgbFB3WSA) 7. Medium [377. Combination Sum IV](/0tWoZsA1SL2IthdPXRkw2w) 8. ? [254. Factor Combinations](/1k0AoqQrRXmvYu48snXZWw) 9. Medium [46. Permutations](/Fht3HQTQRz-6mVeX8DeaDA) 10. Medium [47. Permutations II](/B7g53XcmSAWyggd0nuj1JA) 11. Medium [31. Next Permutation](/kwYWfjZCTuuFnN6Bh3r6_A) 12. Hard [55. Jump Game](https://jaime-lin.medium.com/leetcode-55-jump-game-2496cd718c3e) - Note 1. Please remember how to do combination and permuation. It's really important. --- ### Dynamic Programming - Problems 1. Easy [70. Climbing Stairs](/eSKr1ZwYRXCSEbN-2_kQBw) 2. Medium [62. Unique Paths](/oCI1Z7lpQISmhJujGfQTgw) 3. Medium [63. Unique Paths II](/Dkh7_w3HTWCgm5rUEGOULw) 4. Medium [279. Perfect Squares](/eUtP0coQSs-6UzENS_x-4g) 5. Medium [375. Guess Number Higher or Lower II](https://hackmd.io/J5tuKMt_Sv628o-pNHc4nQ) ### Matrix - Problems 1. Medium [48. Rotate Image](/kpZD6spsRfqPwUlB1rXG-g) 2. Medium [54. Spiral Matrix](/PPcLqOavTL2wFNL-r7T7UA) 3. Medium [59. Spiral Matrix II](/SkU4C895T2Osvhufzqdt-A) 4. Medium [73. Set Matrix Zeroes](/PSTI7UhVSvalKV7BoGm0BQ) 5. Medium [311. Sparse Matrix Multiplication](/AGozxOLmQFWz3UEFXWbfOg) 6. Hard [329. Longest Increasing Path in a Matrix](/gfBOG-VBSNSvKP_FJWNQsA) --- ### Binary Search - Problems 1. Easy [278. First Bad Version](/_qvPJaLbRMmdyWzUykkkFQ) 2. Easy [35. Search Insert Position](/QZG5FcVXSty8hOEwynWOvQ) 3. Medium [33. Search in Rotated Sorted Array](/DoR6t8e3TXyOcy-ZiQLntg) 4. Medium [81. Search in Rotated Sorted Array II](https://hackmd.io/7SisJTJsQfaRJplstjpnjA) 5. Medium [153. Find Minimum in Rotated Sorted Array](/paC_5VYjRMW42v9pmnvA-A) 6. Hard [154. Find Minimum in Rotated Sorted Array II](https://hackmd.io/vniePA2ISZajm6H1m9IwIA) 7. Medium [162. Find Peak Element](https://hackmd.io/2qmLw0Z_S22ACI-7nNWmPA) 8. Easy [374. Guess Number Higher or Lower](https://hackmd.io/W1Gkp9jeTXKIL18Q2n_Mbw) 9. Medium [34. Find First and Last Position of Element in Sorted Array ](https://hackmd.io/VCSVjxZAS7q92R2Vf9fwPw) - Note 1. Binary search summary [Grandyang](https://www.cnblogs.com/grandyang/p/6854825.html) 2. Be very careful of boundary. 3. Finding the best personal binary search implementaion can help you get rid of unnecessary troubles. For me, I like this: ```python= # Python version left, right = 0, len(nums) mid = 0 while left < right: mid = left + (right-left) // 2 if nums[mid] > target: right = mid elif nums[mid] < target: left = mid + 1 else: return mid # Not found return -1 ``` or ```C++= int find(vector<int>& nums, int target) { int left = 0, right = nums.size(); while (left < right) { int mid = left + (right - left) / 2; if (nums[mid] < target) left = mid + 1; else right = mid; } return right; } ``` --- ### Graph 1. Medium 133. [Clone Graph](https://hackmd.io/Bd9YpSXoRpWXjdBa9kkiXQ?both) - Note ```python def bfs(matrix): m = len(matrix[0]) n = len(matrix) visited = [[0] * n for i in range(m)] s = [(0,0)] while s: x, y = s.pop(0) if visited[x][y] == 1: continue else: print(matrix[x][y]) visited[x][y] = 1 if x+1 < m: s.append((x+1, y)) if y+1 < n: s.append((x, y+1)) def dfs(matrix): m = len(matrix[0]) n = len(matrix) visited = [[0] * n for i in range(m)] s = [(0,0)] while s: x, y = s.pop() if visited[x][y] == 1: continue else: print(matrix[x][y]) visited[x][y] = 1 if x+1 < m: s.append((x+1, y)) if y+1 < n: s.append((x, y+1)) ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    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

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully