{"id":17298012,"url":"https://github.com/ziy1-tan/lc-solutions","last_synced_at":"2025-06-15T21:10:47.621Z","repository":{"id":110007373,"uuid":"457269666","full_name":"Ziy1-Tan/LC-Solutions","owner":"Ziy1-Tan","description":"LeetCode Solutions C++ / Py ⏳","archived":false,"fork":false,"pushed_at":"2024-03-16T05:50:21.000Z","size":4034,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T01:44:19.479Z","etag":null,"topics":["leetcode-cpp","leetcode-solutions","python"],"latest_commit_sha":null,"homepage":"","language":"C++","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/Ziy1-Tan.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}},"created_at":"2022-02-09T08:22:06.000Z","updated_at":"2024-08-27T14:24:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"521339cc-d25b-463d-b259-32b452fc2b61","html_url":"https://github.com/Ziy1-Tan/LC-Solutions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ziy1-Tan%2FLC-Solutions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ziy1-Tan%2FLC-Solutions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ziy1-Tan%2FLC-Solutions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ziy1-Tan%2FLC-Solutions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ziy1-Tan","download_url":"https://codeload.github.com/Ziy1-Tan/LC-Solutions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248878538,"owners_count":21176337,"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":["leetcode-cpp","leetcode-solutions","python"],"created_at":"2024-10-15T11:17:48.520Z","updated_at":"2025-04-14T12:22:53.303Z","avatar_url":"https://github.com/Ziy1-Tan.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 刷题顺序\n\n1. [CodeTop](https://codetop.cc/home) 高频题\n2. [LeetCode](https://leetcode.cn/studyplan/top-100-liked/) Hot100\n\n# 题单\n\n## 链表\n\n![linkedlist](./images/2.png)\n\n## 树\n\n![tree](./images/3.png)\n\n## DFS / BFS\n\n![dfs](./images/4.png)\n\n## DP\n\n![dp](./images/5.png)\n\n## 小专题\n\n![other](./images/6.png)\n![other](./images/7.png)\n\n# 复习频率\n\n![freq](./images/1.png)\n\n# Tips\n\n## 二叉树的前中后序遍历（144、94、145）\n\n注意结果打印位置即可\n\n- 前序\n\n```c++\nwhile (root || !stack.empty()) {\n    while (root)\n    {\n        res.push_back(root-\u003eval);\n        stack.push(root);\n        root = root-\u003eleft;\n    }\n\n    root = stack.top();\n    stack.pop();\n    root = root-\u003eright;\n}\n```\n\n- 中序\n\n```c++\nwhile (root || !stack.empty()) {\n    while (root) {\n        stack.push(root);\n        root = root-\u003eleft;\n    }\n\n    root = stack.top();\n    stack.pop();\n    res.push_back(root-\u003eval);\n    root = root-\u003eright;\n}\n```\n\n- 后序\n\n```c++\nwhile (root || !stack.empty()) {\n    while (root) {\n        res.push_back(root-\u003eval);\n        stack.push(root);\n        root = root-\u003eright;\n    }\n\n    root = stack.top();\n    stack.pop();\n    root = root-\u003eleft;\n}\n\nreverse(res.begin(), res.end());\n```\n\n## 组合问题\n\n### 下标记录回溯深度的场景\n\n- 以下标 i 来表示从 i 开始选取避免重复\n- 对结果顺序无要求：[1,2] 和 [2,1] 算是同一种结果\n- 39.组合综合、40.组合总和II、216.组合总和III等\n\n```c++\nfor (int i = idx; i \u003c candidates.size(); i++) {\n    if (rest - candidates[i] \u003e= 0) {\n        path.push_back(candidates[i]);\n        dfs(candidates, rest - candidates[i], i);\n        path.pop_back();\n    }\n}\n```\n\n### used 数组使用的场景\n\n- 用`used[i]`来表示已经选过避免重复\n- 对结果顺序有要求：[1,2] 和 [2,1] 算是不同结果\n- 46.全排列、47.全排列II、剑指Offer38.字符串的排列\n\n```c++\nfor (int i = 0; i \u003c nums.size(); i++) {\n    if (used[i])\n        continue;\n    used[i] = 1;\n    path.push_back(nums[i]);\n    dfs(nums);\n    path.pop_back();\n    used[i] = 0;\n}\n```\n\n### 需要排序剪枝的场景\n\n- 排序后判断`nums[i]==nums[i-1]`跳过选择避免重复\n- 数组中有重复元素：数组 [1,2,2,3]，选择 0、1 元素和选择 0、2 元素产生的结果相同\n- 40.组合总和II、47.全排列II、剑指Offer38.字符串的排列、90.子集II\n\n```c++\nfor (int i = idx; i \u003c candidates.size(); i++) {\n    // 同层不重复，同路径可以重复\n    if (i \u003e idx \u0026\u0026 candidates[i] == candidates[i - 1])\n        continue;\n    ...\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziy1-tan%2Flc-solutions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fziy1-tan%2Flc-solutions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziy1-tan%2Flc-solutions/lists"}