{"id":21178688,"url":"https://github.com/poabob/leetcode","last_synced_at":"2026-05-21T10:02:31.601Z","repository":{"id":178502065,"uuid":"656986886","full_name":"POABOB/leetcode","owner":"POABOB","description":"用於記錄 Leetcode 刷題的 Repo","archived":false,"fork":false,"pushed_at":"2025-03-13T03:55:44.000Z","size":196,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-13T04:26:03.470Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/POABOB.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-22T04:26:26.000Z","updated_at":"2025-03-13T03:55:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"7244f190-ffb3-404e-baa5-5b9591c099a8","html_url":"https://github.com/POABOB/leetcode","commit_stats":null,"previous_names":["poabob/leetcode"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/POABOB%2Fleetcode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/POABOB%2Fleetcode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/POABOB%2Fleetcode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/POABOB%2Fleetcode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/POABOB","download_url":"https://codeload.github.com/POABOB/leetcode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243629222,"owners_count":20322017,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-20T17:23:26.691Z","updated_at":"2026-05-21T10:02:31.595Z","avatar_url":"https://github.com/POABOB.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# leetcode\n\n## 目錄\n\n| No.  | Title                                                      |                                                                 Solution                                                                  | Acceptance | Difficulty | Frequency |\n|:----:|:-----------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------:|:----------:|:----------:|:---------:|\n| 0001 | Two Sum                                                    |                                   [Go](https://github.com/POABOB/leetcode/tree/main/0001.%20Two%20Sum)                                    |   50.1%    |    Easy    |           |\n| 0002 | Add Two Numbers                                            |                           [Go, Java](https://github.com/POABOB/leetcode/tree/main/0002.%20Add%20Two%20Numbers)                            |   45.5%    |   Medium   |           |\n| 0009 | Palindrome Number                                          |                           [Go, Java](https://github.com/POABOB/leetcode/tree/main/0009.%20Palindrome%20Number)                            |   58.8%    |    Easy    |           |\n| 0011 | Container With Most Water                                  |                     [Go, Java](https://github.com/POABOB/leetcode/tree/main/0011.%20Container%20With%20Most%20Water)                      |   57.1%    |   Medium   |           |\n| 0012 | Integer to Roman                                           |                           [Go, Java](https://github.com/POABOB/leetcode/tree/main/0012.%20Integer%20to%20Roman)                           |   67.7%    |   Medium   |           |\n| 0013 | Roman to Integer                                           |                           [Go, Java](https://github.com/POABOB/leetcode/tree/main/0013.%20Roman%20to%20Integer)                           |   64.0%    |    Easy    |           |\n| 0014 | Longest Common Prefix                                      |                        [Go, Java](https://github.com/POABOB/leetcode/tree/main/0014.%20Longest%20Common%20Prefix)                         |   44.8%    |    Easy    |           |\n| 0015 | 3Sum                                                       |                                   [Go, Java](https://github.com/POABOB/leetcode/tree/main/0015.%203Sum)                                   |   36.3%    |   Medium   |           |\n| 0018 | 4Sum                                                       |                                      [Go](https://github.com/POABOB/leetcode/tree/main/0018.%204Sum)                                      |   36.5%    |   Medium   |           |\n| 0019 | Remove Nth Node From End of List                           |               [Go, Java](https://github.com/POABOB/leetcode/tree/main/0019.%20Remove%20Nth%20Node%20From%20End%20of%20List)               |   48.2%    |   Medium   |           |\n| 0020 | Valid Parentheses                                          |                              [Go](https://github.com/POABOB/leetcode/tree/main/0020.%20Valid%20Parentheses)                               |   41.9%    |    Easy    |           |\n| 0021 | Merge Two Sorted Lists                                     |                       [Go, Java](https://github.com/POABOB/leetcode/tree/main/0021.%20Merge%20Two%20Sorted%20Lists)                       |   66.3%    |    Easy    |           |\n| 0023 | Merge k Sorted Lists                                       |                        [Go, Java](https://github.com/POABOB/leetcode/tree/main/0023.%20Merge%20k%20Sorted%20Lists)                        |   56.1%    |    Hard    |           |\n| 0026 | Remove Duplicates from Sorted Array                        |               [Go, Java](https://github.com/POABOB/leetcode/tree/main/0026.%20Remove%20Duplicates%20from%20Sorted%20Array)                |   59.2%    |    Easy    |           |\n| 0027 | Remove Element                                             |                             [Go, Java](https://github.com/POABOB/leetcode/tree/main/0027.%20Remove%20Element)                             |   53.58%   |    Easy    |           |\n| 0028 | Find the Index of the First Occurrence in a String         |   [Go, Java](https://github.com/POABOB/leetcode/tree/main/0028.%20Find%20the%20Index%20of%20the%20First%20Occurrence%20in%20a%20String)   |   44.4%    |    Easy    |           |\n| 0036 | Valid Sudoku                                               |                              [Go, Java](https://github.com/POABOB/leetcode/tree/main/0036.%20Valid%20Sudoku)                              |   61.7%    |   Medium   |           |\n| 0045 | Jump Game II                                               |                             [Go, Java](https://github.com/POABOB/leetcode/tree/main/0045.%20Jump%20Game%20II)                             |   41.1%    |   Medium   |           |\n| 0048 | Rotate Image                                               |                              [Go, Java](https://github.com/POABOB/leetcode/tree/main/0048.%20Rotate%20Image)                              |   77.2%    |   Medium   |           |\n| 0049 | Group Anagrams                                             |                             [Go, Java](https://github.com/POABOB/leetcode/tree/main/0049.%20Group%20Anagrams)                             |   70.4%    |   Medium   |           |\n| 0054 | Spiral Matrix                                              |                             [Go, Java](https://github.com/POABOB/leetcode/tree/main/0054.%20Spiral%20Matrix)                              |   53.0%    |   Medium   |           |\n| 0055 | Jump Game                                                  |                               [Go, Java](https://github.com/POABOB/leetcode/tree/main/0055.%20Jump%20Game)                                |   39.1%    |   Medium   |           |\n| 0058 | Length of Last Word                                        |                        [Go, Java](https://github.com/POABOB/leetcode/tree/main/0058.%20Length%20of%20Last%20Word)                         |   55.3%    |    Easy    |           |\n| 0061 | Rotate List                                                |                              [Go, Java](https://github.com/POABOB/leetcode/tree/main/0061.%20Rotate%20List)                               |   39.4%    |   Medium   |           |\n| 0066 | Plus One                                                   |                                [Go, Java](https://github.com/POABOB/leetcode/tree/main/0066.%20Plus%20One)                                |   47.2%    |    Easy    |           |\n| 0071 | Simplify Path                                              |                             [Go, Java](https://github.com/POABOB/leetcode/tree/main/0071.%20Simplify%20Path)                              |   46.7%    |   Medium   |           |\n| 0073 | Set Matrix Zeroes                                          |                          [Go, Java](https://github.com/POABOB/leetcode/tree/main/0073.%20Set%20Matrix%20Zeroes)                           |   59.0%    |   Medium   |           |\n| 0080 | Remove Duplicates from Sorted Array II                     |             [Go, Java](https://github.com/POABOB/leetcode/tree/main/0080.%20Remove%20Duplicates%20from%20Sorted%20Array%20II)             |   53.6%    |   Medium   |           |\n| 0082 | Remove Duplicates from Sorted List II                      |             [Go, Java](https://github.com/POABOB/leetcode/tree/main/0082.%20Remove%20Duplicates%20from%20Sorted%20List%20II)              |   49.3%    |   Medium   |           |\n| 0086 | Partition List                                             |                             [Go, Java](https://github.com/POABOB/leetcode/tree/main/0086.%20Partition%20List)                             |   58.4%    |   Medium   |           |\n| 0088 | Merge Sorted Array                                         |                          [Go, Java](https://github.com/POABOB/leetcode/tree/main/0088.%20Merge%20Sorted%20Array)                          |   47.23%   |    Easy    |           |\n| 0092 | Reverse Linked List II                                     |                       [Go, Java](https://github.com/POABOB/leetcode/tree/main/0092.%20Reverse%20Linked%20List%20II)                       |   49.1%    |   Medium   |           |\n| 0096 | Unique Binary Search Trees                                 |                        [Go](https://github.com/POABOB/leetcode/tree/main/0096.%20Unique%20Binary%20Search%20Trees)                        |   59.9%    |   Medium   |           |\n| 0100 | Same Tree                                                  |                               [Go, Java](https://github.com/POABOB/leetcode/tree/main/0100.%20Same%20Tree)                                |   64.5%    |    Easy    |           |\n| 0101 | Symmetric Tree                                             |                             [Go, Java](https://github.com/POABOB/leetcode/tree/main/0101.%20Symmetric%20Tree)                             |   58.7%    |    Easy    |           |\n| 0104 | Maximum Depth of Binary Tree                               |                   [Go, Java](https://github.com/POABOB/leetcode/tree/main/0104.%20Maximum%20Depth%20of%20Binary%20Tree)                   |   76.8%    |    Easy    |           |\n| 0105 | Construct Binary Tree from Preorder and Inorder Traversal  | [Go, Java](https://github.com/POABOB/leetcode/tree/main/0105.%20Construct%20Binary%20Tree%20from%20Preorder%20and%20Inorder%20Traversal)  |   66.2%    |   Medium   |           |\n| 0106 | Construct Binary Tree from Inorder and Postorder Traversal | [Go, Java](https://github.com/POABOB/leetcode/tree/main/0106.%20Construct%20Binary%20Tree%20from%20Inorder%20and%20Postorder%20Traversal) |   65.8%    |   Medium   |           |\n| 0108 | Convert Sorted Array to Binary Search Tree                 |          [Go, Java](https://github.com/POABOB/leetcode/tree/main/0108.%20Convert%20Sorted%20Array%20to%20Binary%20Search%20Tree)          |   73.7%    |    Easy    |           |\n| 0112 | Path Sum                                                   |                                [Go, Java](https://github.com/POABOB/leetcode/tree/main/0112.%20Path%20Sum)                                |   52.5%    |    Easy    |           |\n| 0114 | Flatten Binary Tree to Linked List                         |               [Go, Java](https://github.com/POABOB/leetcode/tree/main/0114.%20Flatten%20Binary%20Tree%20to%20Linked%20List)               |   67.8%    |   Medium   |           |\n| 0117 | Populating Next Right Pointers in Each Node II             |       [Go, Java](https://github.com/POABOB/leetcode/tree/main/0117.%20Populating%20Next%20Right%20Pointers%20in%20Each%20Node%20II)       |   55.0%    |   Medium   |           |\n| 0121 | Best Time to Buy and Sell Stock                            |               [Go, Java](https://github.com/POABOB/leetcode/tree/main/0121.%20Best%20Time%20to%20Buy%20and%20Sell%20Stock)                |   54.7%    |    Easy    |           |\n| 0122 | Best Time to Buy and Sell Stock II                         |             [Go, Java](https://github.com/POABOB/leetcode/tree/main/0122.%20Best%20Time%20to%20Buy%20and%20Sell%20Stock%20II)             |   68.7%    |   Medium   |           |\n| 0123 | Best Time to Buy and Sell Stock III                        |            [Go, Java](https://github.com/POABOB/leetcode/tree/main/0123.%20Best%20Time%20to%20Buy%20and%20Sell%20Stock%20III)             |   50.1%    |    Hard    |           |\n| 0124 | Binary Tree Maximum Path Sum                               |                   [Go, Java](https://github.com/POABOB/leetcode/tree/main/0124.%20Binary%20Tree%20Maximum%20Path%20Sum)                   |   41.0%    |    Hard    |           |\n| 0125 | Valid Palindrome                                           |                            [Go, Java](https://github.com/POABOB/leetcode/tree/main/0125.%20Valid%20Palindrome)                            |   50.0%    |    Easy    |           |\n| 0128 | Longest Consecutive Sequence                               |                     [Go, Java](https://github.com/POABOB/leetcode/tree/main/0128.%20Longest%20Consecutive%20Sequence)                     |   47.2%    |   Medium   |           |\n| 0129 | Sum Root to Leaf Numbers                                   |                     [Go, Java](https://github.com/POABOB/leetcode/tree/main/0129.%20Sum%20Root%20to%20Leaf%20Numbers)                     |   68.1%    |   Medium   |           |\n| 0134 | Gas Station                                                |                              [Go, Java](https://github.com/POABOB/leetcode/tree/main/0134.%20Gas%20Station)                               |   45.9%    |   Medium   |           |\n| 0138 | Copy List with Random Pointer                              |                  [Go, Java](https://github.com/POABOB/leetcode/tree/main/0138.%20Copy%20List%20with%20Random%20Pointer)                   |   59.6%    |   Medium   |           |\n| 0141 | Linked List Cycle                                          |                          [Go, Java](https://github.com/POABOB/leetcode/tree/main/0141.%20Linked%20List%20Cycle)                           |   52.0%    |    Easy    |           |\n| 0146 | LRU Cache                                                  |                               [Go, Java](https://github.com/POABOB/leetcode/tree/main/0146.%20LRU%20Cache)                                |   44.5%    |   Medium   |           |\n| 0148 | Sort List                                                  |                               [Go, Java](https://github.com/POABOB/leetcode/tree/main/0148.%20Sort%20List)                                |   61.1%    |   Medium   |           |\n| 0150 | Evaluate Reverse Polish Notation                           |                  [Go, Java](https://github.com/POABOB/leetcode/tree/main/0150.%20Evaluate%20Reverse%20Polish%20Notation)                  |   54.1%    |   Medium   |           |\n| 0151 | Reverse Words in a String                                  |                    [Go, Java](https://github.com/POABOB/leetcode/tree/main/0151.%20Reverse%20Words%20in%20a%20String)                     |   49.7%    |   Medium   |           |\n| 0155 | Min Stack                                                  |                               [Go, Java](https://github.com/POABOB/leetcode/tree/main/0155.%20Min%20Stack)                                |   55.9%    |   Medium   |           |\n| 0167 | Two Sum II - Input Array Is Sorted                         |             [Go, Java](https://github.com/POABOB/leetcode/tree/main/0167.%20Two%20Sum%20II%20-%20Input%20Array%20Is%20Sorted)             |   60.0%    |   Medium   |           |\n| 0169 | Majority Element                                           |                            [Go, Java](https://github.com/POABOB/leetcode/tree/main/0169.%20Majority%20Element)                            |   46.0%    |   Medium   |           |\n| 0172 | Factorial Trailing Zeroes                                  |                      [Go, Java](https://github.com/POABOB/leetcode/tree/main/0172.%20Factorial%20Trailing%20Zeroes)                       |   44.6%    |   Medium   |           |\n| 0173 | Binary Search Tree Iterator                                |                    [Go, Java](https://github.com/POABOB/leetcode/tree/main/0173.%20Binary%20Search%20Tree%20Iterator)                     |   74.4%    |   Medium   |           |\n| 0188 | Best Time to Buy and Sell Stock IV                         |             [Go, Java](https://github.com/POABOB/leetcode/tree/main/0188.%20Best%20Time%20to%20Buy%20and%20Sell%20Stock%20IV)             |   45.8%    |    Hard    |           |\n| 0189 | Rotate Array                                               |                              [Go, Java](https://github.com/POABOB/leetcode/tree/main/0189.%20Rotate%20Array)                              |   39.56%   |   Medium   |           |\n| 0202 | Happy Number                                               |                              [Go, Java](https://github.com/POABOB/leetcode/tree/main/0202.%20Happy%20Number)                              |   57.6%    |    Easy    |           |\n| 0205 | Isomorphic Strings                                         |                           [Go, Java](https://github.com/POABOB/leetcode/tree/main/0205.%20Isomorphic%20Strings)                           |   46.4%    |    Easy    |           |\n| 0219 | Contains Duplicate II                                      |                        [Go, Java](https://github.com/POABOB/leetcode/tree/main/0219.%20Contains%20Duplicate%20II)                         |   48.2%    |    Easy    |           |\n| 0222 | Count Complete Tree Nodes                                  |                     [Go, Java](https://github.com/POABOB/leetcode/tree/main/0222.%20Count%20Complete%20Tree%20Nodes)                      |   69.1%    |    Easy    |           |\n| 0224 | Basic Calculator                                           |                            [Go, Java](https://github.com/POABOB/leetcode/tree/main/0224.%20Basic%20Calculator)                            |   44.9%    |    Hard    |           |\n| 0226 | Invert Binary Tree                                         |                          [Go, Java](https://github.com/POABOB/leetcode/tree/main/0226.%20Invert%20Binary%20Tree)                          |   78.6%    |    Easy    |           |\n| 0236 | Lowest Common Ancestor of a Binary Tree                    |           [Go, Java](https://github.com/POABOB/leetcode/tree/main/0236.%20Lowest%20Common%20Ancestor%20of%20a%20Binary%20Tree)            |   65.9%    |   Medium   |           |\n| 0238 | Product of Array Except Self                               |                   [Go, Java](https://github.com/POABOB/leetcode/tree/main/0238.%20Product%20of%20Array%20Except%20Self)                   |   67.3%    |   Medium   |           |\n| 0242 | Valid Anagram                                              |                             [Go, Java](https://github.com/POABOB/leetcode/tree/main/0242.%20Valid%20Anagram)                              |   66.2%    |    Easy    |           |\n| 0274 | H-Index                                                    |                                 [Go, Java](https://github.com/POABOB/leetcode/tree/main/0274.%20H-Index)                                  |   38.4%    |   Medium   |           |\n| 0289 | Game of Life                                               |                             [Go, Java](https://github.com/POABOB/leetcode/tree/main/0289.%20Game%20of%20Life)                             |   71.0%    |   Medium   |           |\n| 0290 | Word Pattern                                               |                              [Go, Java](https://github.com/POABOB/leetcode/tree/main/0290.%20Word%20Pattern)                              |   42.8%    |    Easy    |           |\n| 0380 | Insert Delete GetRandom O(1)                               |                    [Go, Java](https://github.com/POABOB/leetcode/tree/main/0380.%20Insert%20Delete%20GetRandom%20O(1))                    |   52.8%    |   Medium   |           |\n| 0383 | Ransom Note                                                |                              [Go, Java](https://github.com/POABOB/leetcode/tree/main/0383.%20Ransom%20Note)                               |   63.9%    |    Easy    |           |\n| 0392 | Is Subsequence                                             |                             [Go, Java](https://github.com/POABOB/leetcode/tree/main/0392.%20Is%20Subsequence)                             |   48.2%    |    Easy    |           |\n| 0427 | Construct Quad Tree                                        |                         [Go, Java](https://github.com/POABOB/leetcode/tree/main/0427.%20Construct%20Quad%20Tree)                          |   76.8%    |   Medium   |           |\n\n## 解法公式\n\n### nSum 解法\n\n- 設定終止條件，當 `n \u003c 2`，代表沒有元素可以遍歷，返回 `res`。\n- 如果 `n = 2`，我們可以使用 `Tow Pointer` 的方式來解決。\n- 如果 `n \u003e 2`，在每次迴圈中找出 `target - 當前元素`，之後使用遞迴的方式執行 `nSum(nums, n - 1, i + 1, target)`\n  ，直到 `n = 2` 的時候，找回符合的元素。\n\n```go\nimport \"sort\"\n\nfunc Sum(nums []int, target int) [][]int {\n\tsort.Ints(nums)\n\treturn nSum(nums, 4, 0, target)\n}\n\nfunc nSum(nums []int, n int, start int, target int) [][]int {\n\tlength := len(nums)\n\tvar res [][]int\n\n\tif n \u003c 2 || length \u003c n {\n\t\treturn res\n\t}\n\n\tif n == 2 {\n\t\tsmall, big := start, length-1\n\t\tfor small \u003c big {\n\t\t\tleft, right := nums[small], nums[big]\n\t\t\tsum := left + right\n\n\t\t\tif sum == target {\n\t\t\t\tres = append(res, []int{left, right})\n\t\t\t\tfor small \u003c big \u0026\u0026 nums[small] == left {\n\t\t\t\t\tsmall++\n\t\t\t\t}\n\t\t\t\tfor small \u003c big \u0026\u0026 nums[big] == right {\n\t\t\t\t\tbig--\n\t\t\t\t}\n\t\t\t} else if sum \u003e target {\n\t\t\t\tfor small \u003c big \u0026\u0026 nums[big] == right {\n\t\t\t\t\tbig--\n\t\t\t\t}\n\t\t\t} else if sum \u003c target {\n\t\t\t\tfor small \u003c big \u0026\u0026 nums[small] == left {\n\t\t\t\t\tsmall++\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\ti := start\n\t\tfor i \u003c length {\n\t\t\tnow := nums[i]\n\t\t\tsub := nSum(nums, n-1, i+1, target-now)\n\t\t\tfor _, s := range sub {\n\t\t\t\ts = append(s, now)\n\t\t\t\tres = append(res, s)\n\t\t\t}\n\t\t\tfor i \u003c length \u0026\u0026 nums[i] == now {\n\t\t\t\ti++\n\t\t\t}\n\t\t}\n\t}\n\n\treturn res\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoabob%2Fleetcode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoabob%2Fleetcode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoabob%2Fleetcode/lists"}