diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/156.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/100.exercises/config.json" similarity index 67% rename from "data_source/exercises/\344\270\255\347\255\211/cpp/156.exercises/config.json" rename to "data/1.dailycode\345\210\235\351\230\266/1.cpp/100.exercises/config.json" index 7448b3cb5e374f7eecb88637df658b9f5e95be0b..02f1f1b785114d5354eb7a77903ab1727e699765 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/156.exercises/config.json" +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/100.exercises/config.json" @@ -1,5 +1,5 @@ { - "node_id": "dailycode-3ff87eb146d34897b954ad46df29bcb6", + "node_id": "dailycode-d335de511b684c29bfea723f6d33a0e4", "keywords": [], "children": [], "keywords_must": [], diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/100.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/100.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..be4b137d5de6293fa957b11898e86dc86466e9d7 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/100.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "930f3279f4384794846104506be93185", + "author": "csdn.net", + "keywords": "树,二叉搜索树,数组,分治,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/100.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/100.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..e193cacbc3cb435470d7bbb084cd93b8410bf9e1 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/100.exercises/solution.md" @@ -0,0 +1,96 @@ +# 将有序数组转换为二叉搜索树 + +

给你一个整数数组 nums ,其中元素已经按 升序 排列,请你将其转换为一棵 高度平衡 二叉搜索树。

+ +

高度平衡 二叉树是一棵满足「每个节点的左右两个子树的高度差的绝对值不超过 1 」的二叉树。

+ +

 

+ +

示例 1:

+ +
+输入:nums = [-10,-3,0,5,9]
+输出:[0,-3,9,-10,null,5]
+解释:[0,-10,5,null,-3,null,9] 也将被视为正确答案:
+
+
+ +

示例 2:

+ +
+输入:nums = [1,3]
+输出:[3,1]
+解释:[1,3] 和 [3,1] 都是高度平衡二叉搜索树。
+
+ +

 

+ +

提示:

+ + + + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + TreeNode *sortedArrayToBST(vector &nums) + { + return dfs(nums, 0, nums.size() - 1); + } + + TreeNode *dfs(vector &nums, int left, int right) + { + if (left > right) + return NULL; + int mid = (left + right) / 2; + TreeNode *t = new TreeNode(nums[mid]); + t->left = dfs(nums, left, mid - 1); + t->right = dfs(nums, mid + 1, right); + return t; + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/161.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/101.exercises/config.json" similarity index 67% rename from "data_source/exercises/\344\270\255\347\255\211/cpp/161.exercises/config.json" rename to "data/1.dailycode\345\210\235\351\230\266/1.cpp/101.exercises/config.json" index 4a147f34a3171e6ff42e061bb5c4a58981ee7b21..1e566a356b50acb31b122a14808f52179530efa4 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/161.exercises/config.json" +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/101.exercises/config.json" @@ -1,5 +1,5 @@ { - "node_id": "dailycode-97e15a0f1bdf4c899838b347b1983dc5", + "node_id": "dailycode-a83634532b824c769445b10d596917f6", "keywords": [], "children": [], "keywords_must": [], diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/101.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/101.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..c446541c9dbce296992fabbd3f9406fc4d53cdad --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/101.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "15135e7668e043e7bb577426de5369b2", + "author": "csdn.net", + "keywords": "树,深度优先搜索,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/101.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/101.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..56a72c7157de3f871a550157e8c9929344e66f20 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/101.exercises/solution.md" @@ -0,0 +1,106 @@ +# 平衡二叉树 + +

给定一个二叉树,判断它是否是高度平衡的二叉树。

+ +

本题中,一棵高度平衡二叉树定义为:

+ +
+

一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1 。

+
+ +

 

+ +

示例 1:

+ +
+输入:root = [3,9,20,null,null,15,7]
+输出:true
+
+ +

示例 2:

+ +
+输入:root = [1,2,2,3,3,null,null,4,4]
+输出:false
+
+ +

示例 3:

+ +
+输入:root = []
+输出:true
+
+ +

 

+ +

提示:

+ +
    +
  • 树中的节点数在范围 [0, 5000]
  • +
  • -104 <= Node.val <= 104
  • +
+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + int depth(TreeNode *root) + { + if (root == NULL) + return 0; + int left = depth(root->left); + int right = depth(root->right); + return max(left, right) + 1; + } + + bool isBalanced(TreeNode *root) + { + if (root == NULL) + return true; + if (abs(depth(root->left) - depth(root->right)) > 1) + return false; + else + return isBalanced(root->left) && isBalanced(root->right); + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/177.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/102.exercises/config.json" similarity index 67% rename from "data_source/exercises/\344\270\255\347\255\211/cpp/177.exercises/config.json" rename to "data/1.dailycode\345\210\235\351\230\266/1.cpp/102.exercises/config.json" index 23e96c18d2250dcb674d4636a46c6e308e3db28a..5df90b1b3d78465d16fc55264d72ff5850b8669f 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/177.exercises/config.json" +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/102.exercises/config.json" @@ -1,5 +1,5 @@ { - "node_id": "dailycode-451470417dde4c61a764f65ac405267d", + "node_id": "dailycode-c8023cfe856c4678aa96956db32b5470", "keywords": [], "children": [], "keywords_must": [], diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/102.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/102.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..4a769f333feefe7224aafbc88a71d6b6709ba075 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/102.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "c0299f55bbee4aceb2c6c6ffc245db84", + "author": "csdn.net", + "keywords": "树,深度优先搜索,广度优先搜索,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/102.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/102.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..527bf93653ace3589d306515f19376dba323167c --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/102.exercises/solution.md" @@ -0,0 +1,89 @@ +# 二叉树的最小深度 + +

给定一个二叉树,找出其最小深度。

+ +

最小深度是从根节点到最近叶子节点的最短路径上的节点数量。

+ +

说明:叶子节点是指没有子节点的节点。

+ +

 

+ +

示例 1:

+ +
+输入:root = [3,9,20,null,null,15,7]
+输出:2
+
+ +

示例 2:

+ +
+输入:root = [2,null,3,null,4,null,5,null,6]
+输出:5
+
+ +

 

+ +

提示:

+ +
    +
  • 树中节点数的范围在 [0, 105]
  • +
  • -1000 <= Node.val <= 1000
  • +
+ + +## template + +```cpp + + +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + int minDepth(TreeNode *root) + { + if (!root) + return 0; + int left = minDepth(root->left); + int right = minDepth(root->right); + return (left && right) ? 1 + min(left, right) : 1 + left + right; + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/159.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/103.exercises/config.json" similarity index 67% rename from "data_source/exercises/\344\270\255\347\255\211/cpp/159.exercises/config.json" rename to "data/1.dailycode\345\210\235\351\230\266/1.cpp/103.exercises/config.json" index a86a374a0241df198ac9f4c14f7203fbdb696fa7..7a8f959f7b766f75ebc81fbe447cc372cbf3fd3a 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/159.exercises/config.json" +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/103.exercises/config.json" @@ -1,5 +1,5 @@ { - "node_id": "dailycode-a38c1abb007e45c38ff0968c13fd28ac", + "node_id": "dailycode-fb518fd9317c4e229cee01ac248ce804", "keywords": [], "children": [], "keywords_must": [], diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/103.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/103.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..c441e04cd298493dbf2dbc7eb05b4542171f9e04 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/103.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "3e479d9fb28042b89d7b21dbd2029d20", + "author": "csdn.net", + "keywords": "树,深度优先搜索,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/103.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/103.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..b42acb06bfbfdd1639ae51cec00097c6e87e6871 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/103.exercises/solution.md" @@ -0,0 +1,116 @@ +# 路径总和 + +

给你二叉树的根节点 root 和一个表示目标和的整数 targetSum ,判断该树中是否存在 根节点到叶子节点 的路径,这条路径上所有节点值相加等于目标和 targetSum

+ +

叶子节点 是指没有子节点的节点。

+ +

 

+ +

示例 1:

+ +
+输入:root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22
+输出:true
+
+ +

示例 2:

+ +
+输入:root = [1,2,3], targetSum = 5
+输出:false
+
+ +

示例 3:

+ +
+输入:root = [1,2], targetSum = 0
+输出:false
+
+ +

 

+ +

提示:

+ +
    +
  • 树中节点的数目在范围 [0, 5000]
  • +
  • -1000 <= Node.val <= 1000
  • +
  • -1000 <= targetSum <= 1000
  • +
+ + +## template + +```cpp + +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + bool hasPathSum(TreeNode *root, int sum) + { + bool flag = false; + backTrack(root, sum, flag); + return flag; + } + + void backTrack(TreeNode *root, int sum, bool &flag) + { + if (!root) + { + return; + } + + if (!root->left && !root->right) + { + sum -= root->val; + if (sum == 0) + { + flag = true; + } + sum += root->val; + return; + } + + sum -= root->val; + backTrack(root->left, sum, flag); + backTrack(root->right, sum, flag); + sum += root->val; + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/104.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/104.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..851dd03e818ef97385d1b0ea8bee3f7e029a5143 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/104.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-14e9caac11dc4882b6acbc4e7a4ff49d", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/104.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/104.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..8bc535c54a41952168610a4e786486a457e0b0e1 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/104.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "5f4adb247b224514bbb0d937491de500", + "author": "csdn.net", + "keywords": "数组,动态规划", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/104.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/104.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..e9885e58509b02734101f283f0da25635864ad0e --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/104.exercises/solution.md" @@ -0,0 +1,105 @@ +# 杨辉三角 + +

给定一个非负整数 numRows生成「杨辉三角」的前 numRows 行。

+ +

在「杨辉三角」中,每个数是它左上方和右上方的数的和。

+ +

+ +

 

+ +

示例 1:

+ +
+输入: numRows = 5
+输出: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
+
+ +

示例 2:

+ +
+输入: numRows = 1
+输出: [[1]]
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= numRows <= 30
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + vector> generate(int numRows) + { + + if (numRows <= 0) + { + return {}; + } + if (numRows == 1) + { + return {{1}}; + } + if (numRows == 2) + { + return {{1}, {1, 1}}; + } + + vector> res = {{1}, {1, 1}}; + vector arr; + int row = 1; + while (row < numRows - 1) + { + arr.push_back(1); + for (int i = 0; i < res[row].size() - 1; i++) + { + int temp = 0; + temp = res[row][i] + res[row][i + 1]; + arr.push_back(temp); + } + arr.push_back(1); + res.push_back(arr); + arr.clear(); + row++; + } + return res; + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/105.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/105.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..bf91f5d686489d67b6ea4cbd73767b3049ea9609 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/105.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-163199273b89450f9621cbdf0da4f01b", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/105.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/105.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..d2b47cc409cb802ae742524e0a099c958a65fb62 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/105.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "bbfbabf7e95e4c9b884d37ee321dfe98", + "author": "csdn.net", + "keywords": "数组,动态规划", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/105.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/105.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..de78c7844a17782366bf1425b5b6cbe79fe3d03e --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/105.exercises/solution.md" @@ -0,0 +1,95 @@ +# 杨辉三角 II + +

给定一个非负索引 rowIndex,返回「杨辉三角」的第 rowIndex 行。

+ +

在「杨辉三角」中,每个数是它左上方和右上方的数的和。

+ +

+ +

 

+ +

示例 1:

+ +
+输入: rowIndex = 3
+输出: [1,3,3,1]
+
+ +

示例 2:

+ +
+输入: rowIndex = 0
+输出: [1]
+
+ +

示例 3:

+ +
+输入: rowIndex = 1
+输出: [1,1]
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= rowIndex <= 33
  • +
+ +

 

+ +

进阶:

+ +

你可以优化你的算法到 O(rowIndex) 空间复杂度吗?

+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + vector getRow(int rowIndex) + { + vector res(rowIndex + 1, 1); + for (int i = 0; i < rowIndex + 1; ++i) + { + for (int j = i - 1; j > 0; --j) + { + res[j] = res[j] + res[j - 1]; + } + } + return res; + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/106.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/106.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..3a22e103c35733c34da5ccc41b194e8cbcb8b7bd --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/106.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-26c2393a211f4f74aae41a5c5b6f1194", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/106.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/106.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..217119cbf5ec10b27c73254a2f8b99be0062da7c --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/106.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "9e7555f4e1674542b7f3a4de8eb56e17", + "author": "csdn.net", + "keywords": "数组,动态规划", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/106.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/106.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..55acb60b0b0bb8950e32a4a72fdbc6ae46f882aa --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/106.exercises/solution.md" @@ -0,0 +1,93 @@ +# 买卖股票的最佳时机 + +

给定一个数组 prices ,它的第 i 个元素 prices[i] 表示一支给定股票第 i 天的价格。

+ +

你只能选择 某一天 买入这只股票,并选择在 未来的某一个不同的日子 卖出该股票。设计一个算法来计算你所能获取的最大利润。

+ +

返回你可以从这笔交易中获取的最大利润。如果你不能获取任何利润,返回 0

+ +

 

+ +

示例 1:

+ +
+输入:[7,1,5,3,6,4]
+输出:5
+解释:在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价格 = 6)的时候卖出,最大利润 = 6-1 = 5 。
+     注意利润不能是 7-1 = 6, 因为卖出价格需要大于买入价格;同时,你不能在买入前卖出股票。
+
+ +

示例 2:

+ +
+输入:prices = [7,6,4,3,1]
+输出:0
+解释:在这种情况下, 没有交易完成, 所以最大利润为 0。
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= prices.length <= 105
  • +
  • 0 <= prices[i] <= 104
  • +
+ + +## template + +```cpp + +#include +using namespace std; + +class Solution +{ +public: + int maxProfit(vector &prices) + { + int profit = INT_MIN; + int buy = INT_MAX; + for (int i = 0; i < prices.size(); i++) + { + int temp = prices[i] - buy; + if (temp > profit) + { + profit = temp; + } + if (temp < 0) + { + buy = prices[i]; + } + } + return (profit > 0) ? profit : 0; + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/107.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/107.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..e12a4c14e86d3d1abb9d96774bdf605509b1c22c --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/107.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-0a92b1231f904f52a9bc75a9e427173d", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/107.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/107.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..5d70cdb2aacf346b70b6ecc129181705f1d5b4ad --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/107.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "b91fef5ce7a146aabae6bd7bb2a99add", + "author": "csdn.net", + "keywords": "贪心,数组,动态规划", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/107.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/107.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..b52f61392b66474d0f59237d53f2939ea6537978 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/107.exercises/solution.md" @@ -0,0 +1,95 @@ +# 买卖股票的最佳时机 II + +

给定一个数组 prices ,其中 prices[i] 是一支给定股票第 i 天的价格。

+ +

设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。

+ +

注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。

+ +

 

+ +

示例 1:

+ +
+输入: prices = [7,1,5,3,6,4]
+输出: 7
+解释: 在第 2 天(股票价格 = 1)的时候买入,在第 3 天(股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。
+     随后,在第 4 天(股票价格 = 3)的时候买入,在第 5 天(股票价格 = 6)的时候卖出, 这笔交易所能获得利润 = 6-3 = 3 。
+
+ +

示例 2:

+ +
+输入: prices = [1,2,3,4,5]
+输出: 4
+解释: 在第 1 天(股票价格 = 1)的时候买入,在第 5 天 (股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。
+     注意你不能在第 1 天和第 2 天接连购买股票,之后再将它们卖出。因为这样属于同时参与了多笔交易,你必须在再次购买前出售掉之前的股票。
+
+ +

示例 3:

+ +
+输入: prices = [7,6,4,3,1]
+输出: 0
+解释: 在这种情况下, 没有交易完成, 所以最大利润为 0。
+ +

 

+ +

提示:

+ +
    +
  • 1 <= prices.length <= 3 * 104
  • +
  • 0 <= prices[i] <= 104
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int maxProfit(vector &prices) + { + if (prices.empty()) + return 0; + int cnt = 0; + for (int i = 0; i < prices.size() - 1; ++i) + { + if (prices[i] < prices[i + 1]) + cnt += prices[i + 1] - prices[i]; + } + return cnt; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/108.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/108.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..55b40aad1a708eb3225f2700bb4656c55096a76a --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/108.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-e74a8997c29746c4800782a33e2c7640", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/108.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/108.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..00de483d3ac89bede074848897e157183542f10d --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/108.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "b38a53d95a234b7db1ab99300bb7acc3", + "author": "csdn.net", + "keywords": "双指针,字符串", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/108.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/108.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..3fc65a8156a06fc6ff2dca46ce0c753fcf131e56 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/108.exercises/solution.md" @@ -0,0 +1,101 @@ +# 验证回文串 + +

给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。

+ +

说明:本题中,我们将空字符串定义为有效的回文串。

+ +

 

+ +

示例 1:

+ +
+输入: "A man, a plan, a canal: Panama"
+输出: true
+解释:"amanaplanacanalpanama" 是回文串
+
+ +

示例 2:

+ +
+输入: "race a car"
+输出: false
+解释:"raceacar" 不是回文串
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= s.length <= 2 * 105
  • +
  • 字符串 s 由 ASCII 字符组成
  • +
+ + +## template + +```cpp + +#include +using namespace std; + +class Solution +{ +public: + bool isPalindrome(string s) + { + int left = 0, right; + if ((right = s.size()) == 0) + { + return true; + } + while (left < right) + { + while (left < right && !isalnum(s[left])) + { + left++; + } + while (left < right && !isalnum(s[right])) + { + right--; + } + if (left < right) + { + if (tolower(s[left]) != tolower(s[right])) + { + return false; + } + } + left++; + right--; + } + return true; + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/109.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/109.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..9938071d2364b0a630bd38f69ea964626c88b24a --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/109.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-219df52f601244238513e7de7e2003ed", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/109.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/109.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..3129f7895b8912f6d26eebd729342927acc3e58b --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/109.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "d2339dc4d7f441a8b34f9e4b08c5c6f4", + "author": "csdn.net", + "keywords": "位运算,数组", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/109.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/109.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..eb83a100dbfd91bb34eeba4f950b7582f20961df --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/109.exercises/solution.md" @@ -0,0 +1,67 @@ +# 只出现一次的数字 + +

给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。

+ +

说明:

+ +

你的算法应该具有线性时间复杂度。 你可以不使用额外空间来实现吗?

+ +

示例 1:

+ +
输入: [2,2,1]
+输出: 1
+
+ +

示例 2:

+ +
输入: [4,1,2,1,2]
+输出: 4
+ + +## template + +```cpp + +#include +using namespace std; + +class Solution +{ +public: + int singleNumber(vector &nums) + { + int res = 0; + for (int i = 0; i < nums.size(); i++) + { + res ^= nums[i]; + } + return res; + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/110.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/110.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..33eaf587b5e94aa19cdf7d65d39a84092bfbe67b --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/110.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-55f3974a87a84f75bb2893cb290fde96", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/110.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/110.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..fb0e6885d077f6f8db34a249bfd6646b4b0d3d3a --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/110.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "3294f78b036849119b70d3638940a8d6", + "author": "csdn.net", + "keywords": "哈希表,链表,双指针", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/110.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/110.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..6d587b1cc6d884e9cbb1571da110bbbb9a945d0e --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/110.exercises/solution.md" @@ -0,0 +1,116 @@ +# 环形链表 + +

给定一个链表,判断链表中是否有环。

+ +

如果链表中有某个节点,可以通过连续跟踪 next 指针再次到达,则链表中存在环。 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果 pos-1,则在该链表中没有环。注意:pos 不作为参数进行传递,仅仅是为了标识链表的实际情况。

+ +

如果链表中存在环,则返回 true 。 否则,返回 false

+ +

 

+ +

进阶:

+ +

你能用 O(1)(即,常量)内存解决此问题吗?

+ +

 

+ +

示例 1:

+ +

+ +
输入:head = [3,2,0,-4], pos = 1
+输出:true
+解释:链表中有一个环,其尾部连接到第二个节点。
+
+ +

示例 2:

+ +

+ +
输入:head = [1,2], pos = 0
+输出:true
+解释:链表中有一个环,其尾部连接到第一个节点。
+
+ +

示例 3:

+ +

+ +
输入:head = [1], pos = -1
+输出:false
+解释:链表中没有环。
+
+ +

 

+ +

提示:

+ +
    +
  • 链表中节点的数目范围是 [0, 104]
  • +
  • -105 <= Node.val <= 105
  • +
  • pos-1 或者链表中的一个 有效索引
  • +
+ + +## template + +```cpp +#include +using namespace std; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + bool hasCycle(ListNode *head) + { + + ListNode *faster = head; + ListNode *slower = head; + + if (head == NULL) + return false; + + while (faster != NULL && faster->next != NULL) + { + faster = faster->next->next; + slower = slower->next; + if (faster == slower) + return true; + } + return false; + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/111.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/111.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..ba14cb7ed73defdea3a9c3ca1790b55527c797d0 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/111.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-1651f0143f344641870e403e0fecd732", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/111.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/111.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..fe9072f169a079bf4376984c0d1ca8855c89fa95 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/111.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "d171b0899a7d4fa9b685c5aa42d83779", + "author": "csdn.net", + "keywords": "栈,树,深度优先搜索,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/111.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/111.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..4b9548af0cff603632941f732a3006239b8e1753 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/111.exercises/solution.md" @@ -0,0 +1,110 @@ +# 二叉树的前序遍历 + +

给你二叉树的根节点 root ,返回它节点值的 前序 遍历。

+ +

 

+ +

示例 1:

+ +
+输入:root = [1,null,2,3]
+输出:[1,2,3]
+
+ +

示例 2:

+ +
+输入:root = []
+输出:[]
+
+ +

示例 3:

+ +
+输入:root = [1]
+输出:[1]
+
+ +

示例 4:

+ +
+输入:root = [1,2]
+输出:[1,2]
+
+ +

示例 5:

+ +
+输入:root = [1,null,2]
+输出:[1,2]
+
+ +

 

+ +

提示:

+ +
    +
  • 树中节点数目在范围 [0, 100]
  • +
  • -100 <= Node.val <= 100
  • +
+ +

 

+ +

进阶:递归算法很简单,你可以通过迭代算法完成吗?

+ + +## template + +```cpp + +#include +using namespace std; + +class Solution +{ +private: + void rec(TreeNode *root, vector &ret) + { + if (root != NULL) + { + rec(root->right, ret); + rec(root->left, ret); + ret.push_back(root->val); + } + } + +public: + vector postorderTraversal(TreeNode *root) + { + vector ret; + rec(root, ret); + return ret; + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/112.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/112.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..3ab7641f47863f368e31f5f9c717820cd9860ede --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/112.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-2d3f0bbed569420195f24c6ab63fd904", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/112.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/112.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..29030c32099bcdd7cb9cad4096bec62a022fd8db --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/112.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "01609a836c924ff6beb0ecc2881f99ef", + "author": "csdn.net", + "keywords": "栈,树,深度优先搜索,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/112.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/112.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..94eb07c7fddc194bbda5473d952e9ad075f3b214 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/112.exercises/solution.md" @@ -0,0 +1,70 @@ +# 二叉树的后序遍历 + +

给定一个二叉树,返回它的 后序 遍历。

+ +

示例:

+ +
输入: [1,null,2,3]  
+   1
+    \
+     2
+    /
+   3 
+
+输出: [3,2,1]
+ +

进阶: 递归算法很简单,你可以通过迭代算法完成吗?

+ + +## template + +```cpp + +#include +using namespace std; + +class Solution +{ +public: + vector postorderTraversal(TreeNode *root) + { + dfs(root); + return temp; + } + void dfs(TreeNode *root) + { + if (root == NULL) + return; + dfs(root->left); + dfs(root->right); + temp.push_back(root->val); + } + vector temp; +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/113.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/113.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..682007fae173bc63e5942e8f922b3312af73f671 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/113.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-709d66df256d4328a79b6e8cb3c2d392", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/113.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/113.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..4f7074cbe54eba9decfc6b744cb3f65285f2321e --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/113.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "27b8c45d6f09499fac37e611062195b0", + "author": "csdn.net", + "keywords": "栈,设计", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/113.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/113.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..962ff544283ce0af8233df97ae225c78fbf5e214 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/113.exercises/solution.md" @@ -0,0 +1,111 @@ +# 最小栈 + +

设计一个支持 pushpoptop 操作,并能在常数时间内检索到最小元素的栈。

+ +
    +
  • push(x) —— 将元素 x 推入栈中。
  • +
  • pop() —— 删除栈顶的元素。
  • +
  • top() —— 获取栈顶元素。
  • +
  • getMin() —— 检索栈中的最小元素。
  • +
+ +

 

+ +

示例:

+ +
输入:
+["MinStack","push","push","push","getMin","pop","top","getMin"]
+[[],[-2],[0],[-3],[],[],[],[]]
+
+输出:
+[null,null,null,null,-3,null,0,-2]
+
+解释:
+MinStack minStack = new MinStack();
+minStack.push(-2);
+minStack.push(0);
+minStack.push(-3);
+minStack.getMin();   --> 返回 -3.
+minStack.pop();
+minStack.top();      --> 返回 0.
+minStack.getMin();   --> 返回 -2.
+
+ +

 

+ +

提示:

+ +
    +
  • poptopgetMin 操作总是在 非空栈 上调用。
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class MinStack +{ +public: + stack s; + stack min; + /** initialize your data structure here. */ + MinStack() + { + } + + void push(int x) + { + s.push(x); + if (min.empty() || x <= min.top()) + { + min.push(x); + } + } + + void pop() + { + if (s.top() == min.top()) + min.pop(); + s.pop(); + } + + int top() + { + return s.top(); + } + int getMin() + { + return min.top(); + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/114.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/114.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..8f385b811a74b7879d827a5aa925ff73a609be10 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/114.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-2bc75d75d57b4807a2edf0eb18eb5c8c", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/114.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/114.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..e4116689d660dd11aa933cb0d75d4aa42fb5c27c --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/114.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "2450b377ecaa4e0a9dd4f7d682a4af21", + "author": "csdn.net", + "keywords": "哈希表,链表,双指针", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/114.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/114.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..818e6a2e20b34f40749e4b8edd5c262a3ec9f1a8 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/114.exercises/solution.md" @@ -0,0 +1,126 @@ +# 相交链表 + +

给你两个单链表的头节点 headAheadB ,请你找出并返回两个单链表相交的起始节点。如果两个链表没有交点,返回 null

+ +

图示两个链表在节点 c1 开始相交

+ +

+ +

题目数据 保证 整个链式结构中不存在环。

+ +

注意,函数返回结果后,链表必须 保持其原始结构

+ +

 

+ +

示例 1:

+ +

+ +
+输入:intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3
+输出:Intersected at '8'
+解释:相交节点的值为 8 (注意,如果两个链表相交则不能为 0)。
+从各自的表头开始算起,链表 A 为 [4,1,8,4,5],链表 B 为 [5,0,1,8,4,5]。
+在 A 中,相交节点前有 2 个节点;在 B 中,相交节点前有 3 个节点。
+
+ +

示例 2:

+ +

+ +
+输入:intersectVal = 2, listA = [0,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1
+输出:Intersected at '2'
+解释:相交节点的值为 2 (注意,如果两个链表相交则不能为 0)。
+从各自的表头开始算起,链表 A 为 [0,9,1,2,4],链表 B 为 [3,2,4]。
+在 A 中,相交节点前有 3 个节点;在 B 中,相交节点前有 1 个节点。
+
+ +

示例 3:

+ +

+ +
+输入:intersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2
+输出:null
+解释:从各自的表头开始算起,链表 A 为 [2,6,4],链表 B 为 [1,5]。
+由于这两个链表不相交,所以 intersectVal 必须为 0,而 skipA 和 skipB 可以是任意值。
+这两个链表不相交,因此返回 null 。
+
+ +

 

+ +

提示:

+ +
    +
  • listA 中节点数目为 m
  • +
  • listB 中节点数目为 n
  • +
  • 0 <= m, n <= 3 * 104
  • +
  • 1 <= Node.val <= 105
  • +
  • 0 <= skipA <= m
  • +
  • 0 <= skipB <= n
  • +
  • 如果 listAlistB 没有交点,intersectVal0
  • +
  • 如果 listAlistB 有交点,intersectVal == listA[skipA + 1] == listB[skipB + 1]
  • +
+ +

 

+ +

进阶:你能否设计一个时间复杂度 O(n) 、仅用 O(1) 内存的解决方案?

+ + +## template + +```cpp + +#include +using namespace std; + +class Solution +{ +public: + ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) + { + + if (!headA || !headB) + { + return NULL; + } + + ListNode *cur1 = headA; + ListNode *cur2 = headB; + while (cur1 != cur2) + { + cur1 = cur1 ? cur1->next : headB; + cur2 = cur2 ? cur2->next : headA; + } + return cur1; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/115.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/115.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..632dc84bad20079eae73cd6940ce2455ef58b942 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/115.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-68803d4d5df0420eabfef657c0df9560", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/115.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/115.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..97e92c9025845439fb9e64c6a1069aab6a354f57 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/115.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "e15e9d7a6a034088b2384779c02275af", + "author": "csdn.net", + "keywords": "数组,双指针,二分查找", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/115.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/115.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..38ace9cf84394b3d58c7ef77c3fb10b6f30909ca --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/115.exercises/solution.md" @@ -0,0 +1,103 @@ +# 两数之和 II + +

给定一个已按照 非递减顺序排列  的整数数组 numbers ,请你从数组中找出两个数满足相加之和等于目标数 target

+ +

函数应该以长度为 2 的整数数组的形式返回这两个数的下标值numbers 的下标 从 1 开始计数 ,所以答案数组应当满足 1 <= answer[0] < answer[1] <= numbers.length

+ +

你可以假设每个输入 只对应唯一的答案 ,而且你 不可以 重复使用相同的元素。

+  + +

示例 1:

+ +
+输入:numbers = [2,7,11,15], target = 9
+输出:[1,2]
+解释:2 与 7 之和等于目标数 9 。因此 index1 = 1, index2 = 2 。
+
+ +

示例 2:

+ +
+输入:numbers = [2,3,4], target = 6
+输出:[1,3]
+
+ +

示例 3:

+ +
+输入:numbers = [-1,0], target = -1
+输出:[1,2]
+
+ +

 

+ +

提示:

+ +
    +
  • 2 <= numbers.length <= 3 * 104
  • +
  • -1000 <= numbers[i] <= 1000
  • +
  • numbers非递减顺序 排列
  • +
  • -1000 <= target <= 1000
  • +
  • 仅存在一个有效答案
  • +
+ + +## template + +```cpp + +#include +using namespace std; + +class Solution +{ +public: + vector twoSum(vector &numbers, int target) + { + int low = 0, high = numbers.size() - 1; + while (low < high) + { + int sum = numbers[low] + numbers[high]; + if (sum == target) + { + return {low + 1, high + 1}; + } + if (sum < target) + { + ++low; + } + else + { + --high; + } + } + return {-1, -1}; + } +} +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/116.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/116.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..94e61fcabd31714a033158b8937208ca5e29652e --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/116.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-8337bc578dd54305bcbcf6445d06af30", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/116.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/116.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..746bb1754ee7c729c618497c0e07bd2afe6ebfd3 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/116.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "787031c1bf0b4f81b66999b3f4b42146", + "author": "csdn.net", + "keywords": "数学,字符串", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/116.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/116.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..6e6ad1ee43c310dbcce58ba992ef482f8933f6ec --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/116.exercises/solution.md" @@ -0,0 +1,112 @@ +# Excel表列名称 + +

给你一个整数 columnNumber ,返回它在 Excel 表中相对应的列名称。

+ +

例如:

+ +
+A -> 1
+B -> 2
+C -> 3
+...
+Z -> 26
+AA -> 27
+AB -> 28 
+...
+
+ +

 

+ +

示例 1:

+ +
+输入:columnNumber = 1
+输出:"A"
+
+ +

示例 2:

+ +
+输入:columnNumber = 28
+输出:"AB"
+
+ +

示例 3:

+ +
+输入:columnNumber = 701
+输出:"ZY"
+
+ +

示例 4:

+ +
+输入:columnNumber = 2147483647
+输出:"FXSHRXW"
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= columnNumber <= 231 - 1
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + string convertToTitle(int n) + { + string res; + while (n) + { + int temp = n % 26; + n /= 26; + if (temp) + res.push_back('A' + temp - 1); + else + { + res.push_back('Z'); + n--; + } + } + reverse(res.begin(), res.end()); + return res; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/117.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/117.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..cd9d27729469638e75e8af79f111831c8c01cddd --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/117.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-962b9124033e41d49aa3481c7dfab494", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/117.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/117.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..87e54c15dc3a4adc3d529bfa517a481105c73d13 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/117.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "3063239bef37448aaddac259ac4b4649", + "author": "csdn.net", + "keywords": "数组,哈希表,分治,计数,排序", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/117.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/117.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..fb2b1813d5fbaa74d161ca3da5ad4009bbbadb50 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/117.exercises/solution.md" @@ -0,0 +1,83 @@ +# 多数元素 + +

给定一个大小为 n 的数组,找到其中的多数元素。多数元素是指在数组中出现次数 大于 ⌊ n/2 ⌋ 的元素。

+ +

你可以假设数组是非空的,并且给定的数组总是存在多数元素。

+ +

 

+ +

示例 1:

+ +
+输入:[3,2,3]
+输出:3
+ +

示例 2:

+ +
+输入:[2,2,1,1,1,2,2]
+输出:2
+
+ +

 

+ +

进阶:

+ +
    +
  • 尝试设计时间复杂度为 O(n)、空间复杂度为 O(1) 的算法解决此问题。
  • +
+ + +## template + +```cpp + +#include +using namespace std; + +class Solution +{ +public: + int majorityElement(vector &nums) + { + unordered_map counts; + int majority = 0, cnt = 0; + for (int num : nums) + { + ++counts[num]; + if (counts[num] > cnt) + { + majority = num; + cnt = counts[num]; + } + } + return majority; + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/118.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/118.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..d8340c3cd9e0f30cdd74dc041f37a75de7f50396 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/118.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-bc50522c68bf48fd97e6f613722f66fa", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/118.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/118.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..57d7043585809d2aea4a9e5014398bb42b26d1b0 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/118.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "ba1063921dbe41418dee9ce903777741", + "author": "csdn.net", + "keywords": "数学,字符串", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/118.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/118.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..f9757c1eeb79b51b751792e4b8f4e95120bc9fe2 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/118.exercises/solution.md" @@ -0,0 +1,108 @@ +# Excel表列序号 + +

给你一个字符串 columnTitle ,表示 Excel 表格中的列名称。返回该列名称对应的列序号。

+ +

 

+ +

例如,

+ +
+    A -> 1
+    B -> 2
+    C -> 3
+    ...
+    Z -> 26
+    AA -> 27
+    AB -> 28 
+    ...
+
+ +

 

+ +

示例 1:

+ +
+输入: columnTitle = "A"
+输出: 1
+
+ +

示例 2:

+ +
+输入: columnTitle = "AB"
+输出: 28
+
+ +

示例 3:

+ +
+输入: columnTitle = "ZY"
+输出: 701
+ +

示例 4:

+ +
+输入: columnTitle = "FXSHRXW"
+输出: 2147483647
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= columnTitle.length <= 7
  • +
  • columnTitle 仅由大写英文组成
  • +
  • columnTitle 在范围 ["A", "FXSHRXW"]
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int titleToNumber(string s) + { + + long num = 0; + + for (int i = 0; i < s.size(); i++) + { + num = (num * 26) + (s[i] - 64); + } + return num; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/119.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/119.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..c83c3a754cf0a8c1b762ffa33600be1b7e5a1ebb --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/119.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-345aecfe47a24f5aa0a5a616aa82d801", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/119.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/119.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..bf63c204d2610a00403c739f8475060bb266b0e4 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/119.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "090510ef86b14cb08933325e85f553dd", + "author": "csdn.net", + "keywords": "数学", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/119.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/119.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..3e5d8db58a343703664e0dbcfabe65bf19f290a3 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/119.exercises/solution.md" @@ -0,0 +1,105 @@ +# 阶乘后的零 + +

给定一个整数 n ,返回 n! 结果中尾随零的数量。

+ +

提示 n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1

+ +

 

+ +

示例 1:

+ +
+输入:n = 3
+输出:0
+解释:3! = 6 ,不含尾随 0
+
+ +

示例 2:

+ +
+输入:n = 5
+输出:1
+解释:5! = 120 ,有一个尾随 0
+
+ +

示例 3:

+ +
+输入:n = 0
+输出:0
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= n <= 104
  • +
+ +

 

+ +

进阶:你可以设计并实现对数时间复杂度的算法来解决此问题吗?

+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int trailingZeroes(int n) + { + int numOfZeros = 0; + + while (n > 0) + { + numOfZeros += numOf5(n); + n--; + } + + return numOfZeros; + } + int numOf5(int num) + { + int count = 0; + while ((num > 1) && (num % 5 == 0)) + { + count++; + num /= 5; + } + return count; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/120.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/120.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..9d608750f11f421481cf2b84c3e60a05cd5ca9ad --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/120.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-524ced2fd5dd476bbfa3314db321e961", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/120.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/120.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..3000ac31eac6ec656eeaeffa6b3aa4462734c53e --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/120.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "1bf7c916bc354627b654aff938342c0f", + "author": "csdn.net", + "keywords": "位运算,分治", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/120.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/120.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..d62bba09387b08898f9133ed45f08b41097085ff --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/120.exercises/solution.md" @@ -0,0 +1,93 @@ +# 颠倒二进制位 + +

颠倒给定的 32 位无符号整数的二进制位。

+ +

提示:

+ +
    +
  • 请注意,在某些语言(如 Java)中,没有无符号整数类型。在这种情况下,输入和输出都将被指定为有符号整数类型,并且不应影响您的实现,因为无论整数是有符号的还是无符号的,其内部的二进制表示形式都是相同的。
  • +
  • 在 Java 中,编译器使用二进制补码记法来表示有符号整数。因此,在 示例 2 中,输入表示有符号整数 -3,输出表示有符号整数 -1073741825
  • +
+ +

 

+ +

示例 1:

+ +
+输入:n = 00000010100101000001111010011100
+输出:964176192 (00111001011110000010100101000000)
+解释:输入的二进制串 00000010100101000001111010011100 表示无符号整数 43261596,
+     因此返回 964176192,其二进制表示形式为 00111001011110000010100101000000
+ +

示例 2:

+ +
+输入:n = 11111111111111111111111111111101
+输出:3221225471 (10111111111111111111111111111111)
+解释:输入的二进制串 11111111111111111111111111111101 表示无符号整数 4294967293,
+     因此返回 3221225471 其二进制表示形式为 10111111111111111111111111111111 。
+ +

 

+ +

提示:

+ +
    +
  • 输入是一个长度为 32 的二进制字符串
  • +
+ +

 

+ +

进阶: 如果多次调用这个函数,你将如何优化你的算法?

+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + uint32_t reverseBits(uint32_t n) + { + uint32_t res = 0; + + for (int i = 0; i < 32; i++) + { + res <<= 1; + res |= n & 1; + n >>= 1; + } + + return res; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/121.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/121.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..06c626eba58be2d37c70a8b2deb2e2f6cac004da --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/121.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-e7e53eb27fac437d9d1a3dbdc258d5bf", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/121.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/121.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..1a3dc9a75b3dfd528a8e643718c410b0c0a64a51 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/121.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "e9ed6c10cc8046fdb9c2f303c9827372", + "author": "csdn.net", + "keywords": "位运算", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/121.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/121.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..e1880f15e5a818224870a10f42009a771e3a9a9e --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/121.exercises/solution.md" @@ -0,0 +1,110 @@ +# 位1的个数 + +

编写一个函数,输入是一个无符号整数(以二进制串的形式),返回其二进制表达式中数字位数为 '1' 的个数(也被称为汉明重量)。

+ +

 

+ +

提示:

+ +
    +
  • 请注意,在某些语言(如 Java)中,没有无符号整数类型。在这种情况下,输入和输出都将被指定为有符号整数类型,并且不应影响您的实现,因为无论整数是有符号的还是无符号的,其内部的二进制表示形式都是相同的。
  • +
  • 在 Java 中,编译器使用二进制补码记法来表示有符号整数。因此,在上面的 示例 3 中,输入表示有符号整数 -3
  • +
+ +

 

+ +

示例 1:

+ +
+输入:00000000000000000000000000001011
+输出:3
+解释:输入的二进制串 00000000000000000000000000001011 中,共有三位为 '1'。
+
+ +

示例 2:

+ +
+输入:00000000000000000000000010000000
+输出:1
+解释:输入的二进制串 00000000000000000000000010000000 中,共有一位为 '1'。
+
+ +

示例 3:

+ +
+输入:11111111111111111111111111111101
+输出:31
+解释:输入的二进制串 11111111111111111111111111111101 中,共有 31 位为 '1'。
+ +

 

+ +

提示:

+ +
    +
  • 输入必须是长度为 32二进制串
  • +
+ +
    +
+ +

 

+ +

进阶

+ +
    +
  • 如果多次调用这个函数,你将如何优化你的算法?
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int hammingWeight(uint32_t n) + { + int count = 0; + uint32_t res = 1; + for (int i = 0; i < 32; i++) + { + if (res & n) + { + count++; + } + n >>= 1; + } + return count; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/122.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/122.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..f16e18d0cbb93a2b7cb1a7b1c6a72719ee6babef --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/122.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-15f39c759f9b4aa99bb75b00bcf0580c", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/122.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/122.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..ac58ff5584edcf978227223596c4c88ac3b42737 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/122.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "dd2a5b9e9ed849f5b905fbbd20b230ea", + "author": "csdn.net", + "keywords": "哈希表,数学,双指针", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/122.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/122.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..10954e2884bbeb2bdb400baac55eafbe859ad34c --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/122.exercises/solution.md" @@ -0,0 +1,102 @@ +# 快乐数 + +

编写一个算法来判断一个数 n 是不是快乐数。

+ +

「快乐数」定义为:

+ +
    +
  • 对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和。
  • +
  • 然后重复这个过程直到这个数变为 1,也可能是 无限循环 但始终变不到 1。
  • +
  • 如果 可以变为  1,那么这个数就是快乐数。
  • +
+ +

如果 n 是快乐数就返回 true ;不是,则返回 false

+ +

 

+ +

示例 1:

+ +
+输入:19
+输出:true
+解释:
+12 + 92 = 82
+82 + 22 = 68
+62 + 82 = 100
+12 + 02 + 02 = 1
+
+ +

示例 2:

+ +
+输入:n = 2
+输出:false
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= n <= 231 - 1
  • +
+ + +## template + +```cpp + +#include +using namespace std; + +class Solution +{ +public: + bool isHappy(int n) + { + set s; + while (n != 1) + { + int t = 0; + while (n) + { + t += (n % 10) * (n % 10); + n /= 10; + } + + int size = s.size(); + s.insert(t); + if (size == s.size()) + return false; + n = t; + } + return true; + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/123.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/123.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..e3b65c9a4dffbbb05da3d1b7e2f6b3e2a8603536 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/123.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-ae3f500a3fd948b59a5433ed9e3abee5", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/123.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/123.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..0f461ff3f3178ead82f52fa2d070f8f215d25c26 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/123.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "764671b466ae41c7918438e006b78d38", + "author": "csdn.net", + "keywords": "递归,链表", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/123.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/123.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..4b34eddad1d3a5b53503fb1a9b3657f7768e5aa9 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/123.exercises/solution.md" @@ -0,0 +1,104 @@ +# 移除链表元素 + +给你一个链表的头节点 head 和一个整数 val ,请你删除链表中所有满足 Node.val == val 的节点,并返回 新的头节点 。 +

 

+ +

示例 1:

+ +
+输入:head = [1,2,6,3,4,5,6], val = 6
+输出:[1,2,3,4,5]
+
+ +

示例 2:

+ +
+输入:head = [], val = 1
+输出:[]
+
+ +

示例 3:

+ +
+输入:head = [7,7,7,7], val = 7
+输出:[]
+
+ +

 

+ +

提示:

+ +
    +
  • 列表中的节点数目在范围 [0, 104]
  • +
  • 1 <= Node.val <= 50
  • +
  • 0 <= val <= 50
  • +
+ + +## template + +```cpp +#include +using namespace std; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + ListNode *removeElements(ListNode *head, int val) + { + ListNode *dumynode = new ListNode(0); + dumynode->next = head; + ListNode *fast = dumynode->next; + ListNode *slow = dumynode; + while (fast != NULL) + { + if (fast->val == val) + { + slow->next = slow->next->next; + } + else + { + slow = slow->next; + } + fast = fast->next; + } + ListNode *ret = dumynode->next; + delete dumynode; + return ret; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/124.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/124.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..af598965ab98dc8aa5e259444457c230b07d022c --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/124.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-7259fff1111e46ffa29f196ba542ba00", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/124.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/124.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..ffc08bd15a61fb665a0b79349efb40bf5b0a7f8f --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/124.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "27936a1703b94c82bcc9f781c9194893", + "author": "csdn.net", + "keywords": "数组,数学,枚举,数论", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/124.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/124.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..5aec7be0c0d725dd8cb6ffc09807c59308a3eb60 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/124.exercises/solution.md" @@ -0,0 +1,89 @@ +# 计数质数 + +

统计所有小于非负整数 n 的质数的数量。

+ +

 

+ +

示例 1:

+ +
输入:n = 10
+输出:4
+解释:小于 10 的质数一共有 4 个, 它们是 2, 3, 5, 7 。
+
+ +

示例 2:

+ +
输入:n = 0
+输出:0
+
+ +

示例 3:

+ +
输入:n = 1
+输出:0
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= n <= 5 * 106
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int countPrimes(int n) + { + vector primesMap(n, true); + int count = 0; + for (int i = 2; i < n; i++) + { + if (primesMap[i]) + { + count++; + for (int j = 2 * i; j < n; j += i) + { + primesMap[j] = false; + } + } + } + return count; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/125.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/125.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..02cda2e05b909c1db3c99a80261c6e2142fc87db --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/125.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-0e10486e4e8640adae0e951917a26845", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/125.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/125.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..9117eeee416a667ea011458d638e5f13cbeccd2c --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/125.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "a240d4ffd705492787e87d9cf88bcab4", + "author": "csdn.net", + "keywords": "哈希表,字符串", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/125.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/125.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..b975a7446ef41fee5fb3ee74dc5d5f4a76750842 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/125.exercises/solution.md" @@ -0,0 +1,98 @@ +# 同构字符串 + +

给定两个字符串 和 t,判断它们是否是同构的。

+ +

如果 中的字符可以按某种映射关系替换得到 ,那么这两个字符串是同构的。

+ +

每个出现的字符都应当映射到另一个字符,同时不改变字符的顺序。不同字符不能映射到同一个字符上,相同字符只能映射到同一个字符上,字符可以映射到自己本身。

+ +

 

+ +

示例 1:

+ +
+输入:s = "egg", t = "add"
+输出:true
+
+ +

示例 2:

+ +
+输入:s = "foo", t = "bar"
+输出:false
+ +

示例 3:

+ +
+输入:s = "paper", t = "title"
+输出:true
+ +

 

+ +

提示:

+ +
    +
  • 可以假设 t 长度相同。
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + bool isIsomorphic(string s, string t) + { + vector m(128, -1); + for (int i = 0; i < s.size(); ++i) + { + if (m[s[i]] != -1) + { + if (m[s[i]] != t[i]) + return false; + } + else + { + for (auto v : m) + { + if (v == t[i]) + return false; + } + m[s[i]] = t[i]; + } + } + return true; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/126.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/126.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..c9d067e114fdaadfe2685844ea26f9dd0781083b --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/126.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-88db4509fe484d61a6dcf07943003cb1", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/126.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/126.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..08c173ea1c4adcb2420b6634b04f2f8213435f03 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/126.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "d26956dec2844546a98f1ea107b00a65", + "author": "csdn.net", + "keywords": "递归,链表", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/126.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/126.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..9fd32f3f95c9da6f5543309195259993612160e1 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/126.exercises/solution.md" @@ -0,0 +1,112 @@ +# 反转链表 + +给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。 +
+
+

 

+ +

示例 1:

+ +
+输入:head = [1,2,3,4,5]
+输出:[5,4,3,2,1]
+
+ +

示例 2:

+ +
+输入:head = [1,2]
+输出:[2,1]
+
+ +

示例 3:

+ +
+输入:head = []
+输出:[]
+
+ +

 

+ +

提示:

+ +
    +
  • 链表中节点的数目范围是 [0, 5000]
  • +
  • -5000 <= Node.val <= 5000
  • +
+ +

 

+ +

进阶:链表可以选用迭代或递归方式完成反转。你能否用两种方法解决这道题?

+
+
+ + +## template + +```cpp +#include +using namespace std; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + ListNode *reverseList(ListNode *head) + { + if (head == NULL) + return NULL; + ListNode *node = NULL; + ListNode *temp = head; + ListNode *temp1 = head; + while (true) + { + if (temp->next == NULL) + { + temp1 = temp; + temp1->next = node; + break; + } + temp1 = temp; + temp = temp->next; + temp1->next = node; + node = temp1; + } + return temp1; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/127.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/127.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..0947c089a7348d38db0143bf3d94e5b7b3d2ce8f --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/127.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-510c86fa67d842068f7c3f018e8f89d9", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/127.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/127.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..965b5c3cf3fd90effc8d915addde2af95821fe13 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/127.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "c1b8804fd7a14cef8cd5f20e0f4ff762", + "author": "csdn.net", + "keywords": "数组,哈希表,排序", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/127.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/127.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..a56993f859ae443d5cf342385c797d01e32ef7cd --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/127.exercises/solution.md" @@ -0,0 +1,81 @@ +# 存在重复元素 + +

给定一个整数数组,判断是否存在重复元素。

+ +

如果存在一值在数组中出现至少两次,函数返回 true 。如果数组中每个元素都不相同,则返回 false

+ +

 

+ +

示例 1:

+ +
+输入: [1,2,3,1]
+输出: true
+ +

示例 2:

+ +
+输入: [1,2,3,4]
+输出: false
+ +

示例 3:

+ +
+输入: [1,1,1,3,3,4,3,2,4,2]
+输出: true
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + bool containsDuplicate(vector &nums) + { + if (nums.empty()) + { + return false; + } + sort(nums.begin(), nums.begin() + nums.size()); + for (int i = 0; i < nums.size() - 1; i++) + { + if (nums[i] == nums[i + 1]) + { + return true; + } + } + return false; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/128.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/128.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..790b05b8af9e349b400efb7bf0e84ac30c62c673 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/128.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-6326da4a969f49dc810d995343223f5e", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/128.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/128.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..b70e9b7f551637a9bc14e6bef02ac01d66791e3a --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/128.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "243066531cd64f568c3a8386611c0089", + "author": "csdn.net", + "keywords": "数组,哈希表,滑动窗口", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/128.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/128.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..7f4bbe9e9a2d7784d168e9ac6e2a0635b018f94d --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/128.exercises/solution.md" @@ -0,0 +1,79 @@ +# 存在重复元素 II + +

给定一个整数数组和一个整数 k,判断数组中是否存在两个不同的索引 i 和 j,使得 nums [i] = nums [j],并且 ij 的差的 绝对值 至多为 k

+ +

 

+ +

示例 1:

+ +
输入: nums = [1,2,3,1], k = 3
+输出: true
+ +

示例 2:

+ +
输入: nums = [1,0,1,1], k = 1
+输出: true
+ +

示例 3:

+ +
输入: nums = [1,2,3,1,2,3], k = 2
+输出: false
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + bool containsNearbyDuplicate(vector &nums, int k) + { + int n = nums.size(), idx = 0; + unordered_map nmap; + for (int i = 0; i < n; ++i) + { + auto iter = nmap.find(nums[i]); + if (iter != nmap.end()) + { + if (i - iter->second <= k) + return true; + else + iter->second = i; + } + else + nmap[nums[i]] = i; + } + return false; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/129.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/129.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..3fb9542ee9f9c8eb8dc54e79194a0007e7d6c71c --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/129.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-50e1cb8edc1d4dc19b4d95ab248cbe36", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/129.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/129.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..7d17debd77394d96f68bb6d9a023de1b3cab4fce --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/129.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "86948c5e7a8a44ce9a4c9acc737a3770", + "author": "csdn.net", + "keywords": "栈,设计,队列", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/129.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/129.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..07a8ea7ca0b6a62f8605e636229f3f0e16c5cebb --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/129.exercises/solution.md" @@ -0,0 +1,130 @@ +# 用队列实现栈 + +

请你仅使用两个队列实现一个后入先出(LIFO)的栈,并支持普通栈的全部四种操作(pushtoppopempty)。

+ +

实现 MyStack 类:

+ +
    +
  • void push(int x) 将元素 x 压入栈顶。
  • +
  • int pop() 移除并返回栈顶元素。
  • +
  • int top() 返回栈顶元素。
  • +
  • boolean empty() 如果栈是空的,返回 true ;否则,返回 false
  • +
+ +

 

+ +

注意:

+ +
    +
  • 你只能使用队列的基本操作 —— 也就是 push to backpeek/pop from frontsize 和 is empty 这些操作。
  • +
  • 你所使用的语言也许不支持队列。 你可以使用 list (列表)或者 deque(双端队列)来模拟一个队列 , 只要是标准的队列操作即可。
  • +
+ +

 

+ +

示例:

+ +
+输入:
+["MyStack", "push", "push", "top", "pop", "empty"]
+[[], [1], [2], [], [], []]
+输出:
+[null, null, null, 2, 2, false]
+
+解释:
+MyStack myStack = new MyStack();
+myStack.push(1);
+myStack.push(2);
+myStack.top(); // 返回 2
+myStack.pop(); // 返回 2
+myStack.empty(); // 返回 False
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= x <= 9
  • +
  • 最多调用100pushpoptopempty
  • +
  • 每次调用 poptop 都保证栈不为空
  • +
+ +

 

+ +

进阶:你能否实现每种操作的均摊时间复杂度为 O(1) 的栈?换句话说,执行 n 个操作的总时间复杂度 O(n) ,尽管其中某个操作可能需要比其他操作更长的时间。你可以使用两个以上的队列。

+ + +## template + +```cpp +#include +using namespace std; + +class MyStack +{ +public: + MyStack() + { + } + void push(int x) + { + std::queue temp_queue; + temp_queue.push(x); + while (!_data.empty()) + { + temp_queue.push(_data.front()); + _data.pop(); + } + while (!temp_queue.empty()) + { + _data.push(temp_queue.front()); + temp_queue.pop(); + } + } + int pop() + { + int x = _data.front(); + _data.pop(); + return x; + } + int top() + { + return _data.front(); + } + bool empty() + { + return _data.empty(); + } + +private: + std::queue _data; +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/130.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/130.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..33f85fa0f344e1fa44205005130eccfcc17fe2d9 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/130.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-e1a1c4598bdb483a8b73a902222956df", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/130.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/130.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..520ee5a4b83d7c30bc78067254186c3bf7f6740b --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/130.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "68c7ad63c6ac42af89a763d04013e0f2", + "author": "csdn.net", + "keywords": "树,深度优先搜索,广度优先搜索,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/130.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/130.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..65e7812370ad625806e0f069c5eb9653c701ac37 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/130.exercises/solution.md" @@ -0,0 +1,85 @@ +# 翻转二叉树 + +

翻转一棵二叉树。

+ +

示例:

+ +

输入:

+ +
     4
+   /   \
+  2     7
+ / \   / \
+1   3 6   9
+ +

输出:

+ +
     4
+   /   \
+  7     2
+ / \   / \
+9   6 3   1
+ +

备注:
+这个问题是受到 Max Howell 原问题 启发的 :

+ +
谷歌:我们90%的工程师使用您编写的软件(Homebrew),但是您却无法在面试时在白板上写出翻转二叉树这道题,这太糟糕了。
+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + TreeNode *invertTree(TreeNode *root) + { + if (!root) + { + return root; + } + TreeNode *temp = root->left; + root->left = invertTree(root->right); + root->right = invertTree(temp); + return root; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/131.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/131.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..d91fc776a5d19fd7b7c5f5d9a50199aee16dc110 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/131.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-3ee24b6deba740379e077abdc180342f", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/131.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/131.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..6ef8b113a26cff7895e526da143dfbd6e26e0696 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/131.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "79ea6f8b6f134986bb083e68baeb4266", + "author": "csdn.net", + "keywords": "数组", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/131.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/131.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..7dd8f72164da8f250edfe2916eb489f49574bf37 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/131.exercises/solution.md" @@ -0,0 +1,127 @@ +# 汇总区间 + +

给定一个无重复元素的有序整数数组 nums

+ +

返回 恰好覆盖数组中所有数字最小有序 区间范围列表。也就是说,nums 的每个元素都恰好被某个区间范围所覆盖,并且不存在属于某个范围但不属于 nums 的数字 x

+ +

列表中的每个区间范围 [a,b] 应该按如下格式输出:

+ +
    +
  • "a->b" ,如果 a != b
  • +
  • "a" ,如果 a == b
  • +
+ +

 

+ +

示例 1:

+ +
+输入:nums = [0,1,2,4,5,7]
+输出:["0->2","4->5","7"]
+解释:区间范围是:
+[0,2] --> "0->2"
+[4,5] --> "4->5"
+[7,7] --> "7"
+
+ +

示例 2:

+ +
+输入:nums = [0,2,3,4,6,8,9]
+输出:["0","2->4","6","8->9"]
+解释:区间范围是:
+[0,0] --> "0"
+[2,4] --> "2->4"
+[6,6] --> "6"
+[8,9] --> "8->9"
+
+ +

示例 3:

+ +
+输入:nums = []
+输出:[]
+
+ +

示例 4:

+ +
+输入:nums = [-1]
+输出:["-1"]
+
+ +

示例 5:

+ +
+输入:nums = [0]
+输出:["0"]
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= nums.length <= 20
  • +
  • -231 <= nums[i] <= 231 - 1
  • +
  • nums 中的所有值都 互不相同
  • +
  • nums 按升序排列
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + vector summaryRanges(vector &nums) + { + int n = nums.size(); + vector ans; + int i = 0; + while (i < n) + { + int j = i; + while (j + 1 < n && nums[j + 1] == nums[j] + 1) + j++; + if (i == j) + ans.push_back(to_string(nums[i])); + else + ans.push_back(to_string(nums[i]) + "->" + to_string(nums[j])); + i = j + 1; + } + return ans; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/132.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/132.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..e39d89943313a82fc95676b072010e9e6a7a4699 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/132.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-73795c2480d4451cbba108521a80078c", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/132.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/132.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..e511e4ce6ac501cd83c3c9f53506a1e0733656eb --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/132.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "4ca1d7d6fdc3440390e82ed46d4bed70", + "author": "csdn.net", + "keywords": "位运算,递归,数学", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/132.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/132.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..b2d9ce3c926eceb6370fb1baac6c231b72f62158 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/132.exercises/solution.md" @@ -0,0 +1,105 @@ +# 2 的幂 + +

给你一个整数 n,请你判断该整数是否是 2 的幂次方。如果是,返回 true ;否则,返回 false

+ +

如果存在一个整数 x 使得 n == 2x ,则认为 n 是 2 的幂次方。

+ +

 

+ +

示例 1:

+ +
+输入:n = 1
+输出:true
+解释:20 = 1
+
+ +

示例 2:

+ +
+输入:n = 16
+输出:true
+解释:24 = 16
+
+ +

示例 3:

+ +
+输入:n = 3
+输出:false
+
+ +

示例 4:

+ +
+输入:n = 4
+输出:true
+
+ +

示例 5:

+ +
+输入:n = 5
+输出:false
+
+ +

 

+ +

提示:

+ +
    +
  • -231 <= n <= 231 - 1
  • +
+ +

 

+ +

进阶:你能够不使用循环/递归解决此问题吗?

+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + bool isPowerOfTwo(int n) + { + int cur = 0; + for (int i = 0; i < 31; i++) + { + cur += (n >> i) & 1; + } + return n > 0 && cur == 1; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/133.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/133.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..109d9dd5dbf7560fd24452e9378d051f8af0d42c --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/133.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-541c93e32cbc42deb82573d4759671e5", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/133.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/133.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..22f35787eaf19b1bbb1a836ab42acec2f293c57f --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/133.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "147ed9774f9941238c0c45a42cb896cc", + "author": "csdn.net", + "keywords": "栈,设计,队列", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/133.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/133.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..b3d46a38ff59e482180ca508a202da4a28732393 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/133.exercises/solution.md" @@ -0,0 +1,144 @@ +# 用栈实现队列 + +

请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作(pushpoppeekempty):

+ +

实现 MyQueue 类:

+ +
    +
  • void push(int x) 将元素 x 推到队列的末尾
  • +
  • int pop() 从队列的开头移除并返回元素
  • +
  • int peek() 返回队列开头的元素
  • +
  • boolean empty() 如果队列为空,返回 true ;否则,返回 false
  • +
+ +

 

+ +

说明:

+ +
    +
  • 你只能使用标准的栈操作 —— 也就是只有 push to toppeek/pop from topsize, 和 is empty 操作是合法的。
  • +
  • 你所使用的语言也许不支持栈。你可以使用 list 或者 deque(双端队列)来模拟一个栈,只要是标准的栈操作即可。
  • +
+ +

 

+ +

进阶:

+ +
    +
  • 你能否实现每个操作均摊时间复杂度为 O(1) 的队列?换句话说,执行 n 个操作的总时间复杂度为 O(n) ,即使其中一个操作可能花费较长时间。
  • +
+ +

 

+ +

示例:

+ +
+输入:
+["MyQueue", "push", "push", "peek", "pop", "empty"]
+[[], [1], [2], [], [], []]
+输出:
+[null, null, null, 1, 1, false]
+
+解释:
+MyQueue myQueue = new MyQueue();
+myQueue.push(1); // queue is: [1]
+myQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)
+myQueue.peek(); // return 1
+myQueue.pop(); // return 1, queue is [2]
+myQueue.empty(); // return false
+
+ +
    +
+ +

 

+ +

提示:

+ +
    +
  • 1 <= x <= 9
  • +
  • 最多调用 100pushpoppeekempty
  • +
  • 假设所有操作都是有效的 (例如,一个空的队列不会调用 pop 或者 peek 操作)
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class MyQueue +{ +public: + /** Initialize your data structure here. */ + stack a, b; + + MyQueue() + { + } + + /** Push element x to the back of queue. */ + void push(int x) + { + while (!b.empty()) + { + a.push(b.top()); + b.pop(); + } + b.push(x); + while (!a.empty()) + { + b.push(a.top()); + a.pop(); + } + } + + /** Removes the element from in front of queue and returns that element. */ + int pop() + { + int res = b.top(); + b.pop(); + return res; + } + + /** Get the front element. */ + int peek() + { + return b.top(); + } + + /** Returns whether the queue is empty. */ + bool empty() + { + return b.empty(); + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/134.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/134.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..048320e6854ce365b2dde0341a8132af415d1131 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/134.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-9416ddb972a34cf1aa8a10edf76ce65f", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/134.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/134.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..97b5fda929a80fa57d6584e93c38908a41dd9f50 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/134.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "3fa672cdbfc84d7893fb5d42da794ab2", + "author": "csdn.net", + "keywords": "栈,递归,链表,双指针", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/134.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/134.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..2bd533e93583028741b4afbde7cdc0d6788db3fc --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/134.exercises/solution.md" @@ -0,0 +1,94 @@ +# 回文链表 + +

给你一个单链表的头节点 head ,请你判断该链表是否为回文链表。如果是,返回 true ;否则,返回 false

+ +

 

+ +

示例 1:

+ +
+输入:head = [1,2,2,1]
+输出:true
+
+ +

示例 2:

+ +
+输入:head = [1,2]
+输出:false
+
+ +

 

+ +

提示:

+ +
    +
  • 链表中节点数目在范围[1, 105]
  • +
  • 0 <= Node.val <= 9
  • +
+ +

 

+ +

进阶:你能否用 O(n) 时间复杂度和 O(1) 空间复杂度解决此题?

+ + +## template + +```cpp +#include +using namespace std; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + bool isPalindrome(ListNode *head) + { + vector v; + while (head != NULL) + { + v.push_back(head->val); + head = head->next; + } + for (int i = 0; i < v.size(); i++) + { + if (v[i] != v[v.size() - i - 1]) + return false; + } + return true; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/135.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/135.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..e4f46f6e4a94633c80419ca41b5eef91f9198c70 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/135.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-27db96ec9b784632b5e93fa1cec6df61", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/135.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/135.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..b5514f6f15af73e36450263696282abad8938a50 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/135.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "13e6888b14114d16b05c8513cbdde328", + "author": "csdn.net", + "keywords": "树,深度优先搜索,二叉搜索树,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/135.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/135.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..7ddce001c1764530dd92cc5e45a7419416b3bf5f --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/135.exercises/solution.md" @@ -0,0 +1,92 @@ +# 二叉搜索树的最近公共祖先 + +

给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先。

+ +

百度百科中最近公共祖先的定义为:“对于有根树 T 的两个结点 p、q,最近公共祖先表示为一个结点 x,满足 x 是 p、q 的祖先且 x 的深度尽可能大(一个节点也可以是它自己的祖先)。”

+ +

例如,给定如下二叉搜索树:  root = [6,2,8,0,4,7,9,null,null,3,5]

+ +

+ +

 

+ +

示例 1:

+ +
输入: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8
+输出: 6 
+解释: 节点 2 和节点 8 的最近公共祖先是 6。
+
+ +

示例 2:

+ +
输入: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 4
+输出: 2
+解释: 节点 2 和节点 4 的最近公共祖先是 2, 因为根据定义最近公共祖先节点可以为节点本身。
+ +

 

+ +

说明:

+ +
    +
  • 所有节点的值都是唯一的。
  • +
  • p、q 为不同节点且均存在于给定的二叉搜索树中。
  • +
+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + TreeNode *lowestCommonAncestor(TreeNode *root, TreeNode *p, TreeNode *q) + { + if (root == NULL) + return NULL; + if ((root->val > q->val) && (root->val > p->val)) + return lowestCommonAncestor(root->left, p, q); + else if ((root->val < q->val) && (root->val < p->val)) + return lowestCommonAncestor(root->right, p, q); + return root; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/98.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/98.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..b65dab7e226332e9b6feb8da2014d00e76c98b2c --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/98.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-b1b34d10555f424f9012194aff09f895", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/98.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/98.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..912f2271e97ebbc69bce4d9755c7a3d1a9b36efd --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/98.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "d79649cb8a834b20905d373e6708efce", + "author": "csdn.net", + "keywords": "树,深度优先搜索,广度优先搜索,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/98.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/98.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..747c823ac19b96203039c91914092b38fbbc1398 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/98.exercises/solution.md" @@ -0,0 +1,94 @@ +# 对称二叉树 + +

给定一个二叉树,检查它是否是镜像对称的。

+ +

 

+ +

例如,二叉树 [1,2,2,3,4,4,3] 是对称的。

+ +
    1
+   / \
+  2   2
+ / \ / \
+3  4 4  3
+
+ +

 

+ +

但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的:

+ +
    1
+   / \
+  2   2
+   \   \
+   3    3
+
+ +

 

+ +

进阶:

+ +

你可以运用递归和迭代两种方法解决这个问题吗?

+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + bool haha(TreeNode *l, TreeNode *r) + { + if (!l && !r) + return true; + if (!l || !r) + return false; + if (l->val != r->val) + return false; + return haha(l->right, r->left) & haha(l->left, r->right); + } + bool isSymmetric(TreeNode *root) + { + if (!root) + return true; + return haha(root->left, root->right); + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/99.exercises/config.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/99.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..30d193abd86dd9009b11f9c1a0d1b57d5af3f855 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/99.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-b34e8ed950f64727b2b4653b8433dc22", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/99.exercises/solution.json" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/99.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..2cf31e507b9a8c06750f254644c3ab3ec0acdea9 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/99.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "32cd436081f24793a212d2ea766f0ba1", + "author": "csdn.net", + "keywords": "树,深度优先搜索,广度优先搜索,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/99.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/99.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..dd3a1892c265cd372d21063326cf72490d5332e3 --- /dev/null +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/99.exercises/solution.md" @@ -0,0 +1,79 @@ +# 二叉树的最大深度 + +

给定一个二叉树,找出其最大深度。

+ +

二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。

+ +

说明: 叶子节点是指没有子节点的节点。

+ +

示例:
+给定二叉树 [3,9,20,null,null,15,7]

+ +
    3
+   / \
+  9  20
+    /  \
+   15   7
+ +

返回它的最大深度 3 。

+ + +## template + +```cpp + +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + int maxDepth(TreeNode *root) + { + int depth = 0; + if (root == NULL) + { + return 0; + } + else + { + depth = max(maxDepth(root->left), maxDepth(root->right)); + return 1 + depth; + } + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/100.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/100.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..d017db5ce78ded8a866e0a65744ef616b6f17838 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/100.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-9c576c7dcc0247e2ae923077462c4baa", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/100.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/100.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..2453785c835b7f0ff6d0f160dd016e3c10b486df --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/100.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "aaa09326cb5644cc8065da1415bc2c12", + "author": "csdn.net", + "keywords": "树,深度优先搜索,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/100.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/100.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..436bf0907707e22ef63e184273ea432db94b2d54 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/100.exercises/solution.md" @@ -0,0 +1,137 @@ +# 求根节点到叶节点数字之和 + +给你一个二叉树的根节点 root ,树中每个节点都存放有一个 09 之间的数字。 +
+
+

每条从根节点到叶节点的路径都代表一个数字:

+ +
    +
  • 例如,从根节点到叶节点的路径 1 -> 2 -> 3 表示数字 123
  • +
+ +

计算从根节点到叶节点生成的 所有数字之和

+ +

叶节点 是指没有子节点的节点。

+ +

 

+ +

示例 1:

+ +
+输入:root = [1,2,3]
+输出:25
+解释:
+从根到叶子节点路径 1->2 代表数字 12
+从根到叶子节点路径 1->3 代表数字 13
+因此,数字总和 = 12 + 13 = 25
+ +

示例 2:

+ +
+输入:root = [4,9,0,5,1]
+输出:1026
+解释:
+从根到叶子节点路径 4->9->5 代表数字 495
+从根到叶子节点路径 4->9->1 代表数字 491
+从根到叶子节点路径 4->0 代表数字 40
+因此,数字总和 = 495 + 491 + 40 = 1026
+
+ +

 

+ +

提示:

+ +
    +
  • 树中节点的数目在范围 [1, 1000]
  • +
  • 0 <= Node.val <= 9
  • +
  • 树的深度不超过 10
  • +
+
+
+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + int sumNumbers(TreeNode *root) + { + if (root == nullptr) + return 0; + int result = 0; + vector num; + vector temp; + digui(root, &num, &temp); + for (int i = 0; i < num.size(); i++) + { + result = result + num[i]; + } + return result; + } + void digui(TreeNode *root, vector *num, vector *temp) + { + temp->push_back(root->val); + if (root->left == nullptr && root->right == nullptr) + { + int sum = 0; + for (int i = temp->size() - 1; i >= 0; i--) + { + /*if (i==0 && (*temp)[0]==0) { + continue; + }*/ + int howi = (*temp)[i]; + sum = sum + howi * pow(10, (temp->size() - i - 1)); + } + num->push_back(sum); + temp->pop_back(); + return; + } + if (root->left) + digui(root->left, num, temp); + if (root->right) + digui(root->right, num, temp); + temp->pop_back(); + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/101.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/101.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..74dfb6e02e635daf5de4d7203cfc6fd1f9a90a34 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/101.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-0c3ef2e1bd1242338188dd04275436e9", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/101.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/101.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..107b6055f33311d2eb0318e0a136716c91930d95 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/101.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "da6922e6926a4e50899352935ffd9566", + "author": "csdn.net", + "keywords": "深度优先搜索,广度优先搜索,并查集,数组,矩阵", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/101.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/101.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..cd76118caaaa542366a9d3b83dc06b084409fe3b --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/101.exercises/solution.md" @@ -0,0 +1,131 @@ +# 被围绕的区域 + +给你一个 m x n 的矩阵 board ,由若干字符 'X''O' ,找到所有被 'X' 围绕的区域,并将这些区域里所有的 'O''X' 填充。 +
+
+

 

+ +

示例 1:

+ +
+输入:board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]
+输出:[["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]]
+解释:被围绕的区间不会存在于边界上,换句话说,任何边界上的 'O' 都不会被填充为 'X'。 任何不在边界上,或不与边界上的 'O' 相连的 'O' 最终都会被填充为 'X'。如果两个元素在水平或垂直方向相邻,则称它们是“相连”的。
+
+ +

示例 2:

+ +
+输入:board = [["X"]]
+输出:[["X"]]
+
+ +

 

+ +

提示:

+ +
    +
  • m == board.length
  • +
  • n == board[i].length
  • +
  • 1 <= m, n <= 200
  • +
  • board[i][j]'X''O'
  • +
+
+
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int m, n; + void solve(vector> &board) + { + m = board.size(); + if (!m) + return; + n = board[0].size(); + if (!n) + return; + for (int i = 0; i < m; ++i) + { + if (i == 0 || i == m - 1) + { + for (int j = 0; j < n; ++j) + { + if (board[i][j] == 'O') + dfs(board, i, j); + } + } + else + { + if (board[i][0] == 'O') + dfs(board, i, 0); + if (board[i][n - 1] == 'O') + dfs(board, i, n - 1); + } + } + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; ++j) + { + if (board[i][j] == 'A') + board[i][j] = 'O'; + else + board[i][j] = 'X'; + } + } + void dfs(vector> &board, int i, int j) + { + board[i][j] = 'A'; + if (i - 1 < m && i - 1 >= 0 && j < n && j >= 0 && board[i - 1][j] == 'O') + { + dfs(board, i - 1, j); + } + if (i + 1 < m && i + 1 >= 0 && j < n && j >= 0 && board[i + 1][j] == 'O') + { + dfs(board, i + 1, j); + } + if (i < m && i >= 0 && j - 1 < n && j - 1 >= 0 && board[i][j - 1] == 'O') + { + dfs(board, i, j - 1); + } + if (i < m && i >= 0 && j + 1 < n && j + 1 >= 0 && board[i][j + 1] == 'O') + { + dfs(board, i, j + 1); + } + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/102.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/102.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..e6e7189c470c590bb432fa2c85a0e5631b87174e --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/102.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-6595ec837a47451bb033b3d82cbcf542", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/102.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/102.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..f54885f6076789613939286bafc9c07abf7b24f1 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/102.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "e58bd889e1d14d47b472202ff1401855", + "author": "csdn.net", + "keywords": "字符串,动态规划,回溯", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/102.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/102.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..b8653cf5324782754e27531ed6c35eedfdbdc764 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/102.exercises/solution.md" @@ -0,0 +1,103 @@ +# 分割回文串 + +

给你一个字符串 s,请你将 s 分割成一些子串,使每个子串都是 回文串 。返回 s 所有可能的分割方案。

+ +

回文串 是正着读和反着读都一样的字符串。

+ +

 

+ +

示例 1:

+ +
+输入:s = "aab"
+输出:[["a","a","b"],["aa","b"]]
+
+ +

示例 2:

+ +
+输入:s = "a"
+输出:[["a"]]
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= s.length <= 16
  • +
  • s 仅由小写英文字母组成
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + bool isPali(string s) + { + for (int i = 0; i < s.length() / 2; i++) + if (s[i] != s[s.length() - i - 1]) + return false; + return true; + } + + void dfs(vector> &ans, vector &tmp, int n, string s) + { + if (n == s.length()) + { + ans.push_back(tmp); + return; + } + for (int i = n; i < s.length(); i++) + { + if (isPali(s.substr(n, i - n + 1))) + { + tmp.push_back(s.substr(n, i - n + 1)); + dfs(ans, tmp, i + 1, s); + tmp.pop_back(); + } + } + } + + vector> partition(string s) + { + vector> ans; + vector tmp; + dfs(ans, tmp, 0, s); + return ans; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/103.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/103.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..e99d0bb9b7895d20fd1c88a7827365b5da8a1bc1 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/103.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-2e0242542523489684fe462e57e5dc2d", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/103.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/103.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..064bec575a476db85ff612b72243dfefd217c967 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/103.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "bf408a7721784878b90fb71b52238074", + "author": "csdn.net", + "keywords": "深度优先搜索,广度优先搜索,图,哈希表", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/103.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/103.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..89b5548bc69699af056d1511803de6abb3e61ac2 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/103.exercises/solution.md" @@ -0,0 +1,146 @@ +# 克隆图 + +

给你无向 连通 图中一个节点的引用,请你返回该图的 深拷贝(克隆)。

+ +

图中的每个节点都包含它的值 valint) 和其邻居的列表(list[Node])。

+ +
class Node {
+    public int val;
+    public List<Node> neighbors;
+}
+ +

 

+ +

测试用例格式:

+ +

简单起见,每个节点的值都和它的索引相同。例如,第一个节点值为 1(val = 1),第二个节点值为 2(val = 2),以此类推。该图在测试用例中使用邻接列表表示。

+ +

邻接列表 是用于表示有限图的无序列表的集合。每个列表都描述了图中节点的邻居集。

+ +

给定节点将始终是图中的第一个节点(值为 1)。你必须将 给定节点的拷贝 作为对克隆图的引用返回。

+ +

 

+ +

示例 1:

+ +

+ +
输入:adjList = [[2,4],[1,3],[2,4],[1,3]]
+输出:[[2,4],[1,3],[2,4],[1,3]]
+解释:
+图中有 4 个节点。
+节点 1 的值是 1,它有两个邻居:节点 2 和 4 。
+节点 2 的值是 2,它有两个邻居:节点 1 和 3 。
+节点 3 的值是 3,它有两个邻居:节点 2 和 4 。
+节点 4 的值是 4,它有两个邻居:节点 1 和 3 。
+
+ +

示例 2:

+ +

+ +
输入:adjList = [[]]
+输出:[[]]
+解释:输入包含一个空列表。该图仅仅只有一个值为 1 的节点,它没有任何邻居。
+
+ +

示例 3:

+ +
输入:adjList = []
+输出:[]
+解释:这个图是空的,它不含任何节点。
+
+ +

示例 4:

+ +

+ +
输入:adjList = [[2],[1]]
+输出:[[2],[1]]
+ +

 

+ +

提示:

+ +
    +
  1. 节点数不超过 100 。
  2. +
  3. 每个节点值 Node.val 都是唯一的,1 <= Node.val <= 100
  4. +
  5. 无向图是一个简单图,这意味着图中没有重复的边,也没有自环。
  6. +
  7. 由于图是无向的,如果节点 p 是节点 q 的邻居,那么节点 q 也必须是节点 p 的邻居。
  8. +
  9. 图是连通图,你可以从给定节点访问到所有节点。
  10. +
+ + +## template + +```cpp +#include +using namespace std; + +class Node +{ +public: + int val; + vector neighbors; + + Node() {} + + Node(int _val, vector _neighbors) + { + val = _val; + neighbors = _neighbors; + } +}; + +class Solution +{ +public: + Node *cloneGraph(Node *node) + { + unordered_map m; + return helper(node, m); + } + Node *helper(Node *node, unordered_map &m) + { + if (!node) + return NULL; + if (m.count(node)) + return m[node]; + Node *clone = new Node(node->val); + m[node] = clone; + for (Node *neighbor : node->neighbors) + { + clone->neighbors.push_back(helper(neighbor, m)); + } + return clone; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/104.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/104.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..b865010482f0fdf613e2d8ec9532c920cb02db5c --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/104.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-75dace4205f44a3598936beb6e9bab7a", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/104.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/104.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..9a00f2bd1bf8eaf61b6ec218e75ec38f935bcc4e --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/104.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "1f2b3e0e87e44f42a819c33feb21cce4", + "author": "csdn.net", + "keywords": "贪心,数组", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/104.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/104.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..4786b640caf11260f7e7f9f1bb887428589394bc --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/104.exercises/solution.md" @@ -0,0 +1,110 @@ +# 加油站 + +

在一条环路上有 N 个加油站,其中第 i 个加油站有汽油 gas[i] 升。

+ +

你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i+1 个加油站需要消耗汽油 cost[i] 升。你从其中的一个加油站出发,开始时油箱为空。

+ +

如果你可以绕环路行驶一周,则返回出发时加油站的编号,否则返回 -1。

+ +

说明: 

+ +
    +
  • 如果题目有解,该答案即为唯一答案。
  • +
  • 输入数组均为非空数组,且长度相同。
  • +
  • 输入数组中的元素均为非负数。
  • +
+ +

示例 1:

+ +
输入: 
+gas  = [1,2,3,4,5]
+cost = [3,4,5,1,2]
+
+输出: 3
+
+解释:
+从 3 号加油站(索引为 3 处)出发,可获得 4 升汽油。此时油箱有 = 0 + 4 = 4 升汽油
+开往 4 号加油站,此时油箱有 4 - 1 + 5 = 8 升汽油
+开往 0 号加油站,此时油箱有 8 - 2 + 1 = 7 升汽油
+开往 1 号加油站,此时油箱有 7 - 3 + 2 = 6 升汽油
+开往 2 号加油站,此时油箱有 6 - 4 + 3 = 5 升汽油
+开往 3 号加油站,你需要消耗 5 升汽油,正好足够你返回到 3 号加油站。
+因此,3 可为起始索引。
+ +

示例 2:

+ +
输入: 
+gas  = [2,3,4]
+cost = [3,4,3]
+
+输出: -1
+
+解释:
+你不能从 0 号或 1 号加油站出发,因为没有足够的汽油可以让你行驶到下一个加油站。
+我们从 2 号加油站出发,可以获得 4 升汽油。 此时油箱有 = 0 + 4 = 4 升汽油
+开往 0 号加油站,此时油箱有 4 - 3 + 2 = 3 升汽油
+开往 1 号加油站,此时油箱有 3 - 3 + 3 = 3 升汽油
+你无法返回 2 号加油站,因为返程需要消耗 4 升汽油,但是你的油箱只有 3 升汽油。
+因此,无论怎样,你都不可能绕环路行驶一周。
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int canCompleteCircuit(vector &gas, vector &cost) + { + int index = 0; + int sum = 0; + int csum = 0; + for (int i = 0; i < gas.size(); i++) + { + int temp = gas[i] - cost[i]; + sum += temp; + if (csum > 0) + { + csum += gas[i] - cost[i]; + } + else + { + csum = gas[i] - cost[i]; + index = i; + } + } + return sum >= 0 ? index : -1; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/105.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/105.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..a67408d53dd860395f5095e9f6dc3b5e8f1578b1 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/105.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-0de614ddd4a841aca80d2037ae64bfe9", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/105.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/105.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..582f78c609f894ec5399250bd88e34bcbecc859f --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/105.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "afa57be04ea148dcbe59f3b4b37f9e99", + "author": "csdn.net", + "keywords": "位运算,数组", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/105.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/105.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..9c0c0a45c1f7f91520adf83815a676fec8b012bb --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/105.exercises/solution.md" @@ -0,0 +1,100 @@ +# 只出现一次的数字 II + +

给你一个整数数组 nums ,除某个元素仅出现 一次 外,其余每个元素都恰出现 三次 。请你找出并返回那个只出现了一次的元素。

+ +

 

+ +

示例 1:

+ +
+输入:nums = [2,2,3,2]
+输出:3
+
+ +

示例 2:

+ +
+输入:nums = [0,1,0,1,0,1,99]
+输出:99
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= nums.length <= 3 * 104
  • +
  • -231 <= nums[i] <= 231 - 1
  • +
  • nums 中,除某个元素仅出现 一次 外,其余每个元素都恰出现 三次
  • +
+ +

 

+ +

进阶:你的算法应该具有线性时间复杂度。 你可以不使用额外空间来实现吗?

+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int singleNumber(vector &nums) + { + sort(nums.begin(), nums.end()); + int res = 0; + int i = 0; + for (int j = 1; j < nums.size(); j++) + { + if (nums[j] != nums[i]) + { + if (j - i == 1) + { + res = nums[i]; + break; + } + else + { + i = j; + } + } + } + if (i == nums.size() - 1) + { + res = nums[i]; + } + return res; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/106.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/106.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..3c1ca34b11e3f5bcde7926790388a979c812b40a --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/106.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-ee972a8c3ad94ef4937a12be5da23849", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/106.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/106.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..a92f062db0a7f59ff4661c26b830e16d0432020e --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/106.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "504efc590cbb42e49757004b04b3e4e8", + "author": "csdn.net", + "keywords": "哈希表,链表", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/106.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/106.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..ff6fecccfc730f9f343ed12eecc8bfc021e7752d --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/106.exercises/solution.md" @@ -0,0 +1,153 @@ +# 复制带随机指针的链表 + +

给你一个长度为 n 的链表,每个节点包含一个额外增加的随机指针 random ,该指针可以指向链表中的任何节点或空节点。

+ +

构造这个链表的 深拷贝。 深拷贝应该正好由 n全新 节点组成,其中每个新节点的值都设为其对应的原节点的值。新节点的 next 指针和 random 指针也都应指向复制链表中的新节点,并使原链表和复制链表中的这些指针能够表示相同的链表状态。复制链表中的指针都不应指向原链表中的节点

+ +

例如,如果原链表中有 XY 两个节点,其中 X.random --> Y 。那么在复制链表中对应的两个节点 xy ,同样有 x.random --> y

+ +

返回复制链表的头节点。

+ +

用一个由 n 个节点组成的链表来表示输入/输出中的链表。每个节点用一个 [val, random_index] 表示:

+ +
    +
  • val:一个表示 Node.val 的整数。
  • +
  • random_index:随机指针指向的节点索引(范围从 0 到 n-1);如果不指向任何节点,则为  null 。
  • +
+ +

你的代码 接受原链表的头节点 head 作为传入参数。

+ +

 

+ +

示例 1:

+ +

+ +
+输入:head = [[7,null],[13,0],[11,4],[10,2],[1,0]]
+输出:[[7,null],[13,0],[11,4],[10,2],[1,0]]
+
+ +

示例 2:

+ +

+ +
+输入:head = [[1,1],[2,1]]
+输出:[[1,1],[2,1]]
+
+ +

示例 3:

+ +

+ +
+输入:head = [[3,null],[3,0],[3,null]]
+输出:[[3,null],[3,0],[3,null]]
+
+ +

示例 4:

+ +
+输入:head = []
+输出:[]
+解释:给定的链表为空(空指针),因此返回 null。
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= n <= 1000
  • +
  • -10000 <= Node.val <= 10000
  • +
  • Node.random 为空(null)或指向链表中的节点。
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Node +{ +public: + int val; + Node *next; + Node *random; + + Node() {} + + Node(int _val, Node *_next, Node *_random) + { + val = _val; + next = _next; + random = _random; + } +}; + +class Solution +{ +public: + Node *copyRandomList(Node *head) + { + std::map node_map; + std::vector node_vec; + Node *ptr = head; + int i = 0; + while (ptr) + { + + node_vec.push_back(new Node(ptr->val, NULL, NULL)); + node_map[ptr] = i; + ptr = ptr->next; + i++; + } + node_vec.push_back(0); + ptr = head; + i = 0; + while (ptr) + { + node_vec[i]->next = node_vec[i + 1]; + if (ptr->random) + { + int id = node_map[ptr->random]; + node_vec[i]->random = node_vec[id]; + } + ptr = ptr->next; + i++; + } + return node_vec[0]; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/107.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/107.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..22715667ed2861d4c54c44038be147000057c452 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/107.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-7ab771c2a0454a8d88061ebc100eb41e", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/107.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/107.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..d4371f9efd3e294ff834305328ea60cf5b586c04 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/107.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "a999e9a2aa0e4d8f945cfe6efca6fab9", + "author": "csdn.net", + "keywords": "字典树,记忆化搜索,哈希表,字符串,动态规划", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/107.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/107.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..9d33833a9a1e8b8b3d1323b49412da4da6f7137d --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/107.exercises/solution.md" @@ -0,0 +1,94 @@ +# 单词拆分 + +

给定一个非空字符串 s 和一个包含非空单词的列表 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。

+ +

说明:

+ +
    +
  • 拆分时可以重复使用字典中的单词。
  • +
  • 你可以假设字典中没有重复的单词。
  • +
+ +

示例 1:

+ +
输入: s = "leetcode", wordDict = ["leet", "code"]
+输出: true
+解释: 返回 true 因为 "leetcode" 可以被拆分成 "leet code"。
+
+ +

示例 2:

+ +
输入: s = "applepenapple", wordDict = ["apple", "pen"]
+输出: true
+解释: 返回 true 因为 "applepenapple" 可以被拆分成 "apple pen apple"。
+     注意你可以重复使用字典中的单词。
+
+ +

示例 3:

+ +
输入: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"]
+输出: false
+
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + bool wordBreak(string s, vector &wordDict) + { + map tmp; + for (int i = 0; i < wordDict.size(); i++) + { + tmp[wordDict[i]]++; + } + int n = s.length(); + vector res(n + 1, false); + res[0] = true; + for (int i = 0; i <= n; i++) + { + for (int j = 0; j < i; j++) + { + if (res[j] && tmp[s.substr(j, i - j)]) + { + res[i] = true; + break; + } + } + } + return res[n]; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/108.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/108.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..8f8f54626d4517b98f5b1d486a20df9e567c8e54 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/108.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-c86e8718d6a14cbcb86586cfeded8a86", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/108.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/108.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..cb710842da2862ddca0ed998f6573a2c2b6e5cb5 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/108.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "c57e84df7922455895cfc253eff07450", + "author": "csdn.net", + "keywords": "哈希表,链表,双指针", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/108.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/108.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..d926ada5126c44532acd7b23a7d93420d2f33e2b --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/108.exercises/solution.md" @@ -0,0 +1,125 @@ +# 环形链表 II + +

给定一个链表,返回链表开始入环的第一个节点。 如果链表无环,则返回 null

+ +

为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果 pos-1,则在该链表中没有环。注意,pos 仅仅是用于标识环的情况,并不会作为参数传递到函数中。

+ +

说明:不允许修改给定的链表。

+ +

进阶:

+ +
    +
  • 你是否可以使用 O(1) 空间解决此题?
  • +
+ +

 

+ +

示例 1:

+ +

+ +
+输入:head = [3,2,0,-4], pos = 1
+输出:返回索引为 1 的链表节点
+解释:链表中有一个环,其尾部连接到第二个节点。
+
+ +

示例 2:

+ +

+ +
+输入:head = [1,2], pos = 0
+输出:返回索引为 0 的链表节点
+解释:链表中有一个环,其尾部连接到第一个节点。
+
+ +

示例 3:

+ +

+ +
+输入:head = [1], pos = -1
+输出:返回 null
+解释:链表中没有环。
+
+ +

 

+ +

提示:

+ +
    +
  • 链表中节点的数目范围在范围 [0, 104]
  • +
  • -105 <= Node.val <= 105
  • +
  • pos 的值为 -1 或者链表中的一个有效索引
  • +
+ + +## template + +```cpp +#include +using namespace std; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + ListNode *detectCycle(ListNode *head) + { + ListNode *slow, *fast, *p; + slow = fast = p = head; + while (fast && fast->next) + { + slow = slow->next; + fast = fast->next->next; + + if (slow == fast) + { + while (p != slow) + { + p = p->next; + slow = slow->next; + } + return p; + } + } + + return nullptr; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/109.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/109.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..a816e91c4defb30546019c35a0c56253168d8b11 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/109.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-0f4fa52ce6504716996db85e4c9e493a", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/109.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/109.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..72a3c8d807c0e291dde34f358d263fa30e8d656a --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/109.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "f5a81fc3e5a040ea8e0429a1e3cf941f", + "author": "csdn.net", + "keywords": "栈,递归,链表,双指针", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/109.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/109.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..7872033b6dec78880fb797e5e033a2135f516c0f --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/109.exercises/solution.md" @@ -0,0 +1,121 @@ +# 重排链表 + +

给定一个单链表 L 的头节点 head ,单链表 L 表示为:

+ +

 L→ L→ … → Ln-1 → L
+请将其重新排列后变为:

+ +

L→ L→ L→ Ln-1 → L→ Ln-2 → …

+ +

不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。

+ +

 

+ +

示例 1:

+ +

+ +
+输入: head = [1,2,3,4]
+输出: [1,4,2,3]
+ +

示例 2:

+ +

+ +
+输入: head = [1,2,3,4,5]
+输出: [1,5,2,4,3]
+ +

 

+ +

提示:

+ +
    +
  • 链表的长度范围为 [1, 5 * 104]
  • +
  • 1 <= node.val <= 1000
  • +
+ + +## template + +```cpp +#include +using namespace std; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + void reorderList(ListNode *head) + { + ListNode *l1 = head, *l2 = head; + ListNode *tep = head; + int len = 0; + while (tep) + { + len++; + tep = tep->next; + } + if (len <= 2) + return; + int len1 = len / 2 + len % 2; + int len2 = len / 2; + for (int i = 0; i < len1 - 1; i++) + { + head = head->next; + } + l2 = head->next; + head->next = nullptr; + head = l1; + stack stk; + while (l2) + { + stk.push(l2); + l2 = l2->next; + } + while (!stk.empty()) + { + tep = stk.top(); + stk.pop(); + tep->next = l1->next; + l1->next = tep; + l1 = tep->next; + } + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/110.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/110.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..0e9e000fdccd4f93c849371f9c63b419854f70fc --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/110.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-a60d5b2274744417bc065e034719adb5", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/110.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/110.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..3cd7bf7d5ea20c2ba1411d4832b2b0ac47ff697c --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/110.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "6925248d8d4b4971ace262cdfc82e08b", + "author": "csdn.net", + "keywords": "设计,哈希表,链表,双向链表", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/110.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/110.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..b8c24e16f256f896055e481bafefab3cd668c5ef --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/110.exercises/solution.md" @@ -0,0 +1,150 @@ +# LRU 缓存机制 + +
运用你所掌握的数据结构,设计和实现一个  LRU (最近最少使用) 缓存机制
+ +
+
+

实现 LRUCache 类:

+ +
    +
  • LRUCache(int capacity) 以正整数作为容量 capacity 初始化 LRU 缓存
  • +
  • int get(int key) 如果关键字 key 存在于缓存中,则返回关键字的值,否则返回 -1
  • +
  • void put(int key, int value) 如果关键字已经存在,则变更其数据值;如果关键字不存在,则插入该组「关键字-值」。当缓存容量达到上限时,它应该在写入新数据之前删除最久未使用的数据值,从而为新的数据值留出空间。
  • +
+ +

 

+
+
+ +

进阶:你是否可以在 O(1) 时间复杂度内完成这两种操作?

+ +

 

+ +

示例:

+ +
+输入
+["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"]
+[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]
+输出
+[null, null, null, 1, null, -1, null, -1, 3, 4]
+
+解释
+LRUCache lRUCache = new LRUCache(2);
+lRUCache.put(1, 1); // 缓存是 {1=1}
+lRUCache.put(2, 2); // 缓存是 {1=1, 2=2}
+lRUCache.get(1);    // 返回 1
+lRUCache.put(3, 3); // 该操作会使得关键字 2 作废,缓存是 {1=1, 3=3}
+lRUCache.get(2);    // 返回 -1 (未找到)
+lRUCache.put(4, 4); // 该操作会使得关键字 1 作废,缓存是 {4=4, 3=3}
+lRUCache.get(1);    // 返回 -1 (未找到)
+lRUCache.get(3);    // 返回 3
+lRUCache.get(4);    // 返回 4
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= capacity <= 3000
  • +
  • 0 <= key <= 10000
  • +
  • 0 <= value <= 105
  • +
  • 最多调用 2 * 105getput
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class LRUCache +{ +private: + int _cap; + + list> cache; + + unordered_map>::iterator> umap; + +public: + LRUCache(int capacity) + { + _cap = capacity; + } + + int get(int key) + { + auto iter = umap.find(key); + if (iter == umap.end()) + return -1; + + pair kv = *umap[key]; + cache.erase(umap[key]); + cache.push_front(kv); + umap[key] = cache.begin(); + + return kv.second; + } + + void put(int key, int value) + { + auto iter = umap.find(key); + if (iter != umap.end()) + { + + cache.erase(umap[key]); + cache.push_front(make_pair(key, value)); + umap[key] = cache.begin(); + + return; + } + + if (cache.size() == _cap) + { + + auto iter = cache.back(); + umap.erase(iter.first); + cache.pop_back(); + + cache.push_front(make_pair(key, value)); + umap[key] = cache.begin(); + } + else + { + cache.push_front(make_pair(key, value)); + umap[key] = cache.begin(); + } + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/111.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/111.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..1eca10031248df8b48d6b18c7702b05394f96cf9 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/111.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-36ed7137f34d4fd2b2b5e101ce9756bb", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/111.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/111.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..ae2c83a827f7a1377e0cc81c4c2960918629b4bf --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/111.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "bc206a68afdd49898d978634851b9566", + "author": "csdn.net", + "keywords": "链表,排序", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/111.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/111.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..cd8e1e2b0a50a6d67db52790c849b328b4f08bc1 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/111.exercises/solution.md" @@ -0,0 +1,96 @@ +# 对链表进行插入排序 + +

对链表进行插入排序。

+ +


+插入排序的动画演示如上。从第一个元素开始,该链表可以被认为已经部分排序(用黑色表示)。
+每次迭代时,从输入数据中移除一个元素(用红色表示),并原地将其插入到已排好序的链表中。

+ +

 

+ +

插入排序算法:

+ +
    +
  1. 插入排序是迭代的,每次只移动一个元素,直到所有元素可以形成一个有序的输出列表。
  2. +
  3. 每次迭代中,插入排序只从输入数据中移除一个待排序的元素,找到它在序列中适当的位置,并将其插入。
  4. +
  5. 重复直到所有输入数据插入完为止。
  6. +
+ +

 

+ +

示例 1:

+ +
输入: 4->2->1->3
+输出: 1->2->3->4
+
+ +

示例 2:

+ +
输入: -1->5->3->4->0
+输出: -1->0->3->4->5
+
+ + +## template + +```cpp +#include +using namespace std; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + ListNode *insertionSortList(ListNode *head) + { + ListNode *dummy = new ListNode(0, head); + ListNode + *prev = dummy, + *lastSorted = head, + *curr = head->next; + + while (curr) + { + lastSorted->next = curr->next; + curr->next = prev->next; + prev->next = curr; + curr = lastSorted->next; + } + return dummy->next; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/112.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/112.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..7e56dc7033d3f642daa7cbb47d01aa3961b5c93d --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/112.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-0eb990da86e340998c215d3a1d8aa859", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/112.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/112.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..3e630df8ba1a13763e5c1ce5682d4ddec1096866 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/112.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "0f14c22af5474598bd0f688223cb0c68", + "author": "csdn.net", + "keywords": "链表,双指针,分治,排序,归并排序", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/112.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/112.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..517ce6fbefb4a2b49be2e2ba215c58a23f8f7a4b --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/112.exercises/solution.md" @@ -0,0 +1,132 @@ +# 排序链表 + +

给你链表的头结点 head ,请将其按 升序 排列并返回 排序后的链表

+ +

进阶:

+ +
    +
  • 你可以在 O(n log n) 时间复杂度和常数级空间复杂度下,对链表进行排序吗?
  • +
+ +

 

+ +

示例 1:

+ +
+输入:head = [4,2,1,3]
+输出:[1,2,3,4]
+
+ +

示例 2:

+ +
+输入:head = [-1,5,3,4,0]
+输出:[-1,0,3,4,5]
+
+ +

示例 3:

+ +
+输入:head = []
+输出:[]
+
+ +

 

+ +

提示:

+ +
    +
  • 链表中节点的数目在范围 [0, 5 * 104] 内
  • +
  • -105 <= Node.val <= 105
  • +
+ + +## template + +```cpp +#include +using namespace std; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + ListNode *sortList(ListNode *head) + { + return mergesort(head); + } + ListNode *mergesort(ListNode *node) + { + if (!node || !node->next) + return node; + ListNode *fast = node; + ListNode *slow = node; + ListNode *brek = node; + while (fast && fast->next) + { + fast = fast->next->next; + brek = slow; + slow = slow->next; + } + brek->next = nullptr; + ListNode *l1 = mergesort(node); + ListNode *l2 = mergesort(slow); + return merge(l1, l2); + } + ListNode *merge(ListNode *l1, ListNode *l2) + { + if (l1 == NULL) + { + return l2; + } + if (l2 == NULL) + { + return l1; + } + if (l1->val < l2->val) + { + l1->next = merge(l1->next, l2); + return l1; + } + else + { + l2->next = merge(l2->next, l1); + return l2; + } + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/113.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/113.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..db69f78c170f7bbfd71190fbf0679194892e579f --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/113.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-f69b5024f7ea4a72811393706d30e524", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/113.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/113.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..6c92d05e6ef833742ad573a010c6f11f2ea8a0e9 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/113.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "d6df7d868e7648678eb11fff0e8eda92", + "author": "csdn.net", + "keywords": "栈,数组,数学", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/113.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/113.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..a6d1f9be85ca18aaef3c67d4c8cf421ab6dad598 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/113.exercises/solution.md" @@ -0,0 +1,144 @@ +# 逆波兰表达式求值 + +

根据 逆波兰表示法,求表达式的值。

+ +

有效的算符包括 +-*/ 。每个运算对象可以是整数,也可以是另一个逆波兰表达式。

+ +

 

+ +

说明:

+ +
    +
  • 整数除法只保留整数部分。
  • +
  • 给定逆波兰表达式总是有效的。换句话说,表达式总会得出有效数值且不存在除数为 0 的情况。
  • +
+ +

 

+ +

示例 1:

+ +
+输入:tokens = ["2","1","+","3","*"]
+输出:9
+解释:该算式转化为常见的中缀算术表达式为:((2 + 1) * 3) = 9
+
+ +

示例 2:

+ +
+输入:tokens = ["4","13","5","/","+"]
+输出:6
+解释:该算式转化为常见的中缀算术表达式为:(4 + (13 / 5)) = 6
+
+ +

示例 3:

+ +
+输入:tokens = ["10","6","9","3","+","-11","*","/","*","17","+","5","+"]
+输出:22
+解释:
+该算式转化为常见的中缀算术表达式为:
+  ((10 * (6 / ((9 + 3) * -11))) + 17) + 5
+= ((10 * (6 / (12 * -11))) + 17) + 5
+= ((10 * (6 / -132)) + 17) + 5
+= ((10 * 0) + 17) + 5
+= (0 + 17) + 5
+= 17 + 5
+= 22
+ +

 

+ +

提示:

+ +
    +
  • 1 <= tokens.length <= 104
  • +
  • tokens[i] 要么是一个算符("+""-""*""/"),要么是一个在范围 [-200, 200] 内的整数
  • +
+ +

 

+ +

逆波兰表达式:

+ +

逆波兰表达式是一种后缀表达式,所谓后缀就是指算符写在后面。

+ +
    +
  • 平常使用的算式则是一种中缀表达式,如 ( 1 + 2 ) * ( 3 + 4 )
  • +
  • 该算式的逆波兰表达式写法为 ( ( 1 2 + ) ( 3 4 + ) * )
  • +
+ +

逆波兰表达式主要有以下两个优点:

+ +
    +
  • 去掉括号后表达式无歧义,上式即便写成 1 2 + 3 4 + * 也可以依据次序计算出正确结果。
  • +
  • 适合用栈操作运算:遇到数字则入栈;遇到算符则取出栈顶两个数字进行计算,并将结果压入栈中。
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int evalRPN(vector &tokens) + { + stack num; + for (int i = 0; i < tokens.size(); ++i) + { + if (tokens[i] == "+" || tokens[i] == "-" || tokens[i] == "*" || tokens[i] == "/") + { + int j; + int a = num.top(); + num.pop(); + int b = num.top(); + num.pop(); + if (tokens[i] == "+") + j = b + a; + else if (tokens[i] == "-") + j = b - a; + else if (tokens[i] == "*") + j = b * a; + else + j = b / a; + num.push(j); + } + else + { + num.push(stoi(tokens[i])); + } + } + return num.top(); + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/114.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/114.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..18273cb0d618c91704eabe4d5333dc03aceae889 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/114.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-05046db437fa4f03bd4e5f082a388673", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/114.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/114.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..4d775285c7aaaf7804f01157742760c6982393de --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/114.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "cd5c9fb0e79a4ff6814d13a0db4ce918", + "author": "csdn.net", + "keywords": "双指针,字符串", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/114.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/114.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..4c58948bd19e52958d3c9c068314af2e3bbd4bd7 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/114.exercises/solution.md" @@ -0,0 +1,161 @@ +# 翻转字符串里的单词 + +

给你一个字符串 s ,逐个翻转字符串中的所有 单词

+ +

单词 是由非空格字符组成的字符串。s 中使用至少一个空格将字符串中的 单词 分隔开。

+ +

请你返回一个翻转 s 中单词顺序并用单个空格相连的字符串。

+ +

说明:

+ +
    +
  • 输入字符串 s 可以在前面、后面或者单词间包含多余的空格。
  • +
  • 翻转后单词间应当仅用一个空格分隔。
  • +
  • 翻转后的字符串中不应包含额外的空格。
  • +
+ +

 

+ +

示例 1:

+ +
+输入:s = "the sky is blue"
+输出:"blue is sky the"
+
+ +

示例 2:

+ +
+输入:s = "  hello world  "
+输出:"world hello"
+解释:输入字符串可以在前面或者后面包含多余的空格,但是翻转后的字符不能包括。
+
+ +

示例 3:

+ +
+输入:s = "a good   example"
+输出:"example good a"
+解释:如果两个单词间有多余的空格,将翻转后单词间的空格减少到只含一个。
+
+ +

示例 4:

+ +
+输入:s = "  Bob    Loves  Alice   "
+输出:"Alice Loves Bob"
+
+ +

示例 5:

+ +
+输入:s = "Alice does not even like bob"
+输出:"bob like even not does Alice"
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= s.length <= 104
  • +
  • s 包含英文大小写字母、数字和空格 ' '
  • +
  • s至少存在一个 单词
  • +
+ +
    +
+ +

 

+ +

进阶:

+ +
    +
  • 请尝试使用 O(1) 额外空间复杂度的原地解法。
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + string reverseWords(string s) + { + splitStr(s); + return joinStr(); + } + +private: + void splitStr(string s) + { + if (s == "") + return; + int len = s.length(); + string tmp = ""; + for (int i = 0; i < len; i++) + { + if (s[i] == ' ' && tmp != "") + { + myStack.push(tmp); + tmp = ""; + continue; + } + if (s[i] == ' ') + continue; + tmp += s[i]; + } + if (tmp != "") + myStack.push(tmp); + return; + } + + string joinStr() + { + if (myStack.empty()) + return ""; + string s = ""; + while (!myStack.empty()) + { + s += myStack.top(); + s += " "; + myStack.pop(); + } + return s.substr(0, s.length() - 1); + } + + stack myStack; +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/115.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/115.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..92b4d313218aea0df694d973fbcc6388f7bbd4ff --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/115.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-e33c5f27e8214636a42bc8cf443ac7dc", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/115.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/115.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..e8ceb43bfea6c60e66cb027bd1036b5d97ff04d2 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/115.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "5aef5bb4e105434789d7066ad7b6d9c5", + "author": "csdn.net", + "keywords": "数组,动态规划", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/115.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/115.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..9bbd637cf9b2c929e18d1395e8ce7d52b8db4b1e --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/115.exercises/solution.md" @@ -0,0 +1,74 @@ +# 乘积最大子数组 + +

给你一个整数数组 nums ,请你找出数组中乘积最大的连续子数组(该子数组中至少包含一个数字),并返回该子数组所对应的乘积。

+ +

 

+ +

示例 1:

+ +
输入: [2,3,-2,4]
+输出: 6
+解释: 子数组 [2,3] 有最大乘积 6。
+
+ +

示例 2:

+ +
输入: [-2,0,-1]
+输出: 0
+解释: 结果不能为 2, 因为 [-2,-1] 不是子数组。
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int maxProduct(vector &nums) + { + int ans = -10000000; + int n = nums.size(); + int max1 = 1, min1 = 1, mx, mn; + for (int i = 0; i < n; i++) + { + mx = max1; + mn = min1; + max1 = max(mx * nums[i], max(nums[i], mn * nums[i])); + min1 = min(mn * nums[i], min(nums[i], mx * nums[i])); + ans = max(max1, ans); + } + return ans; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/116.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/116.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..0e4e10875e0d4b152a5e722b625296c5a05d6e1c --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/116.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-d7d3abfcdce548ab912b7845ab999a96", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/116.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/116.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..501ceb169e7c656128cb547bf99e7b34ff2da593 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/116.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "5e95ff14e3e34ca8b0c3e643ce327dd3", + "author": "csdn.net", + "keywords": "数组,二分查找", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/116.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/116.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..b6e6404fe90e691802f0a68783768952456f25e5 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/116.exercises/solution.md" @@ -0,0 +1,104 @@ +# 寻找旋转排序数组中的最小值 + +已知一个长度为 n 的数组,预先按照升序排列,经由 1n旋转 后,得到输入数组。例如,原数组 nums = [0,1,2,4,5,6,7] 在变化后可能得到: +
    +
  • 若旋转 4 次,则可以得到 [4,5,6,7,0,1,2]
  • +
  • 若旋转 7 次,则可以得到 [0,1,2,4,5,6,7]
  • +
+ +

注意,数组 [a[0], a[1], a[2], ..., a[n-1]] 旋转一次 的结果为数组 [a[n-1], a[0], a[1], a[2], ..., a[n-2]]

+ +

给你一个元素值 互不相同 的数组 nums ,它原来是一个升序排列的数组,并按上述情形进行了多次旋转。请你找出并返回数组中的 最小元素

+ +

 

+ +

示例 1:

+ +
+输入:nums = [3,4,5,1,2]
+输出:1
+解释:原数组为 [1,2,3,4,5] ,旋转 3 次得到输入数组。
+
+ +

示例 2:

+ +
+输入:nums = [4,5,6,7,0,1,2]
+输出:0
+解释:原数组为 [0,1,2,4,5,6,7] ,旋转 4 次得到输入数组。
+
+ +

示例 3:

+ +
+输入:nums = [11,13,15,17]
+输出:11
+解释:原数组为 [11,13,15,17] ,旋转 4 次得到输入数组。
+
+ +

 

+ +

提示:

+ +
    +
  • n == nums.length
  • +
  • 1 <= n <= 5000
  • +
  • -5000 <= nums[i] <= 5000
  • +
  • nums 中的所有整数 互不相同
  • +
  • nums 原来是一个升序排序的数组,并进行了 1n 次旋转
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int findMin(vector &nums) + { + int left = 0, right = nums.size() - 1; + int mid = (left + right) / 2; + while (left < right) + { + mid = (left + right) / 2; + if (nums[mid] > nums[right]) + left = mid + 1; + else + right = mid; + } + return nums[left]; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/117.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/117.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..30b384ab8bc9e65a9b4c16ccbfddc1054694f7d1 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/117.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-dd9ab1f390244fc09b52747485de90a5", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/117.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/117.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..13a3fefdd2a52181f131514bf76a57a92797ea49 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/117.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "b64fe0d514344234a872ab6ccb13bb92", + "author": "csdn.net", + "keywords": "数组,二分查找", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/117.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/117.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..355c99ca11d4bdc24bf2611bb9a5ef49cc839fd7 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/117.exercises/solution.md" @@ -0,0 +1,101 @@ +# 寻找峰值 + +

峰值元素是指其值严格大于左右相邻值的元素。

+ +

给你一个整数数组 nums,找到峰值元素并返回其索引。数组可能包含多个峰值,在这种情况下,返回 任何一个峰值 所在位置即可。

+ +

你可以假设 nums[-1] = nums[n] = -∞

+ +

你必须实现时间复杂度为 O(log n) 的算法来解决此问题。

+ +

 

+ +

示例 1:

+ +
+输入:nums = [1,2,3,1]
+输出:2
+解释:3 是峰值元素,你的函数应该返回其索引 2。
+ +

示例 2:

+ +
+输入:nums = [1,2,1,3,5,6,4]
+输出:1 或 5 
+解释:你的函数可以返回索引 1,其峰值元素为 2;
+     或者返回索引 5, 其峰值元素为 6。
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= nums.length <= 1000
  • +
  • -231 <= nums[i] <= 231 - 1
  • +
  • 对于所有有效的 i 都有 nums[i] != nums[i + 1]
  • +
+ + +## template + +```cpp + +#include +using namespace std; + +class Solution +{ +public: + int findPeakElement(vector &nums) + { + int l = 0, r = nums.size() - 1; + while (l < r) + { + int mid = l + (r - l) / 2; + if (nums[mid] > nums[mid + 1]) + { + if (mid == 0 || nums[mid] > nums[mid - 1]) + return mid; + else + r = mid; + } + else + { + if (mid + 1 == nums.size() - 1 || nums[mid + 1] > nums[mid + 2]) + return mid + 1; + else + l = mid + 1; + } + } + return l; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/118.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/118.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..29da4c31aac15f4879dc9f808829068b40411906 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/118.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-5e49fb70f7ba4fa581a2b1e1aa9afeca", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/118.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/118.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..ce89d688b6761b606d4be0770152f13d09d055a3 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/118.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "18a0dcf78cd549869b8437e46fba25bf", + "author": "csdn.net", + "keywords": "双指针,字符串", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/118.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/118.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..2fe69070c906edb350411139b58de6e28b0e0d6d --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/118.exercises/solution.md" @@ -0,0 +1,142 @@ +# 比较版本号 + +

给你两个版本号 version1version2 ,请你比较它们。

+ +

版本号由一个或多个修订号组成,各修订号由一个 '.' 连接。每个修订号由 多位数字 组成,可能包含 前导零 。每个版本号至少包含一个字符。修订号从左到右编号,下标从 0 开始,最左边的修订号下标为 0 ,下一个修订号下标为 1 ,以此类推。例如,2.5.330.1 都是有效的版本号。

+ +

比较版本号时,请按从左到右的顺序依次比较它们的修订号。比较修订号时,只需比较 忽略任何前导零后的整数值 。也就是说,修订号 1 和修订号 001 相等 。如果版本号没有指定某个下标处的修订号,则该修订号视为 0 。例如,版本 1.0 小于版本 1.1 ,因为它们下标为 0 的修订号相同,而下标为 1 的修订号分别为 010 < 1

+ +

返回规则如下:

+ +
    +
  • 如果 version1 version2 返回 1
  • +
  • 如果 version1 version2 返回 -1
  • +
  • 除此之外返回 0
  • +
+ +

 

+ +

示例 1:

+ +
+输入:version1 = "1.01", version2 = "1.001"
+输出:0
+解释:忽略前导零,"01" 和 "001" 都表示相同的整数 "1"
+
+ +

示例 2:

+ +
+输入:version1 = "1.0", version2 = "1.0.0"
+输出:0
+解释:version1 没有指定下标为 2 的修订号,即视为 "0"
+
+ +

示例 3:

+ +
+输入:version1 = "0.1", version2 = "1.1"
+输出:-1
+解释:version1 中下标为 0 的修订号是 "0",version2 中下标为 0 的修订号是 "1" 。0 < 1,所以 version1 < version2
+
+ +

示例 4:

+ +
+输入:version1 = "1.0.1", version2 = "1"
+输出:1
+
+ +

示例 5:

+ +
+输入:version1 = "7.5.2.4", version2 = "7.5.3"
+输出:-1
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= version1.length, version2.length <= 500
  • +
  • version1version2 仅包含数字和 '.'
  • +
  • version1version2 都是 有效版本号
  • +
  • version1version2 的所有修订号都可以存储在 32 位整数
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int compareVersion(string version1, string version2) + { + int val1, val2; + int idx1 = 0, idx2 = 0; + while (idx1 < version1.length() || idx2 < version2.length()) + { + val1 = 0; + while (idx1 < version1.length()) + { + if (version1[idx1] == '.') + { + ++idx1; + break; + } + val1 = val1 * 10 + (version1[idx1] - '0'); + idx1++; + } + + val2 = 0; + while (idx2 < version2.length()) + { + if (version2[idx2] == '.') + { + idx2++; + break; + } + val2 = val2 * 10 + (version2[idx2] - '0'); + idx2++; + } + if (val1 > val2) + return 1; + if (val1 < val2) + return -1; + } + return 0; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/119.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/119.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..93a37bbadba2b36761148fead8b541ac39760285 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/119.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-fac5c17f457d4cf4b5cf2636c80ffa31", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/119.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/119.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..44a339c4b1ee63e9970472d413ead011a32f5c59 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/119.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "1d66b4dc149845938d464a2b38b724f2", + "author": "csdn.net", + "keywords": "哈希表,数学,字符串", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/119.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/119.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..0df460df108875a8eb98ee69ffa1c68996be4c06 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/119.exercises/solution.md" @@ -0,0 +1,130 @@ +# 分数到小数 + +

给定两个整数,分别表示分数的分子 numerator 和分母 denominator,以 字符串形式返回小数

+ +

如果小数部分为循环小数,则将循环的部分括在括号内。

+ +

如果存在多个答案,只需返回 任意一个

+ +

对于所有给定的输入,保证 答案字符串的长度小于 104

+ +

 

+ +

示例 1:

+ +
+输入:numerator = 1, denominator = 2
+输出:"0.5"
+
+ +

示例 2:

+ +
+输入:numerator = 2, denominator = 1
+输出:"2"
+
+ +

示例 3:

+ +
+输入:numerator = 2, denominator = 3
+输出:"0.(6)"
+
+ +

示例 4:

+ +
+输入:numerator = 4, denominator = 333
+输出:"0.(012)"
+
+ +

示例 5:

+ +
+输入:numerator = 1, denominator = 5
+输出:"0.2"
+
+ +

 

+ +

提示:

+ +
    +
  • -231 <= numerator, denominator <= 231 - 1
  • +
  • denominator != 0
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + string fractionToDecimal(int numerator, int denominator) + { + if (denominator == 0) + return ""; + string ans; + if ((numerator > 0 && denominator < 0) || (numerator < 0 && denominator > 0)) + ans = "-"; + long long num = abs(static_cast(numerator)); + long long den = abs(static_cast(denominator)); + long long quo = num / den; + long long rem = num % den; + + ans = ans + to_string(quo); + if (!rem) + return ans; + + ans += "."; + unordered_map u_m; + string s = ""; + int pos = 0; + while (rem) + { + if (u_m.find(rem) != u_m.end()) + { + s.insert(u_m[rem], "("); + s += ")"; + return ans + s; + } + u_m[rem] = pos++; + s += to_string((rem * 10) / den); + rem = (rem * 10) % den; + } + return ans + s; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/120.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/120.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..5a516f1a7eb2acbea0814536dfdd2d95b744dccb --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/120.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-4a38b31d688641b9843b28b4f373d6e2", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/120.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/120.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..2239ff4f9945d7a5980c8e839b2fefc6eebad7c4 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/120.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "1de12a0f075f46649a65be099ca6af08", + "author": "csdn.net", + "keywords": "栈,树,设计,二叉搜索树,二叉树,迭代器", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/120.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/120.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..1e7b0621453a107ce7105cb075967d0a66f0d4c2 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/120.exercises/solution.md" @@ -0,0 +1,147 @@ +# 二叉搜索树迭代器 + +实现一个二叉搜索树迭代器类BSTIterator ,表示一个按中序遍历二叉搜索树(BST)的迭代器: +
+
+
    +
  • BSTIterator(TreeNode root) 初始化 BSTIterator 类的一个对象。BST 的根节点 root 会作为构造函数的一部分给出。指针应初始化为一个不存在于 BST 中的数字,且该数字小于 BST 中的任何元素。
  • +
  • boolean hasNext() 如果向指针右侧遍历存在数字,则返回 true ;否则返回 false
  • +
  • int next()将指针向右移动,然后返回指针处的数字。
  • +
+ +

注意,指针初始化为一个不存在于 BST 中的数字,所以对 next() 的首次调用将返回 BST 中的最小元素。

+
+
+ +

你可以假设 next() 调用总是有效的,也就是说,当调用 next() 时,BST 的中序遍历中至少存在一个下一个数字。

+ +

 

+ +

示例:

+ +
+输入
+["BSTIterator", "next", "next", "hasNext", "next", "hasNext", "next", "hasNext", "next", "hasNext"]
+[[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []]
+输出
+[null, 3, 7, true, 9, true, 15, true, 20, false]
+
+解释
+BSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]);
+bSTIterator.next();    // 返回 3
+bSTIterator.next();    // 返回 7
+bSTIterator.hasNext(); // 返回 True
+bSTIterator.next();    // 返回 9
+bSTIterator.hasNext(); // 返回 True
+bSTIterator.next();    // 返回 15
+bSTIterator.hasNext(); // 返回 True
+bSTIterator.next();    // 返回 20
+bSTIterator.hasNext(); // 返回 False
+
+ +

 

+ +

提示:

+ +
    +
  • 树中节点的数目在范围 [1, 105]
  • +
  • 0 <= Node.val <= 106
  • +
  • 最多调用 105hasNextnext 操作
  • +
+ +

 

+ +

进阶:

+ +
    +
  • 你可以设计一个满足下述条件的解决方案吗?next()hasNext() 操作均摊时间复杂度为 O(1) ,并使用 O(h) 内存。其中 h 是树的高度。
  • +
+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class BSTIterator +{ +public: + BSTIterator(TreeNode *root) + { + + for (; root != nullptr; root = root->left) + { + sti_.push(root); + } + } + + /** @return the next smallest number */ + int next() + { + + TreeNode *smallest = sti_.top(); + sti_.pop(); + int val = smallest->val; + + smallest = smallest->right; + for (; smallest != nullptr; smallest = smallest->left) + { + sti_.push(smallest); + } + return val; + } + + /** @return whether we have a next smallest number */ + bool hasNext() + { + return !sti_.empty(); + } + +private: + stack sti_; +}; + +/** + * Your BSTIterator object will be instantiated and called as such: + * BSTIterator* obj = new BSTIterator(root); + * int param_1 = obj->next(); + * bool param_2 = obj->hasNext(); + */ + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/121.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/121.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..6536bbc917fd7b9ac06f9c858eb85eb74b1fcf3d --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/121.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-734b902304404565abebe151f9f77153", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/121.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/121.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..626c52cc6ca374b2666bacea0afb5c1bc381e99d --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/121.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "6a83c0e417c64208bca61e383ecaa225", + "author": "csdn.net", + "keywords": "贪心,字符串,排序", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/121.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/121.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..64b10c112350e317610f777cfb12a06200c9ea78 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/121.exercises/solution.md" @@ -0,0 +1,113 @@ +# 最大数 + +

给定一组非负整数 nums,重新排列每个数的顺序(每个数不可拆分)使之组成一个最大的整数。

+ +

注意:输出结果可能非常大,所以你需要返回一个字符串而不是整数。

+ +

 

+ +

示例 1:

+ +
+输入nums = [10,2]
+输出:"210"
+ +

示例 2:

+ +
+输入nums = [3,30,34,5,9]
+输出:"9534330"
+
+ +

示例 3:

+ +
+输入nums = [1]
+输出:"1"
+
+ +

示例 4:

+ +
+输入nums = [10]
+输出:"10"
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= nums.length <= 100
  • +
  • 0 <= nums[i] <= 109
  • +
+ + +## template + +```cpp +#include +using namespace std; + +bool compare(string a, string b) +{ + string s1 = a + b; + string s2 = b + a; + return s1 > s2; +} + +class Solution +{ +public: + string largestNumber(vector &nums) + { + string res = ""; + int n = nums.size(); + vector tmp; + for (int i = 0; i < n; i++) + { + tmp.push_back(to_string(nums[i])); + } + sort(tmp.begin(), tmp.end(), compare); + for (int i = 0; i < tmp.size(); i++) + { + res += tmp[i]; + } + if ('0' == res[0]) + { + return "0"; + } + else + { + return res; + } + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/122.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/122.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..b0ac088f11bd06ce5f6d95fdabeacb4c4fabc2b6 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/122.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-6bfbac883a8f424d89c5d4bd00c1166a", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/122.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/122.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..f46b74e8ad1156cf9771c7901319f6159b901e00 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/122.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "f2f407f63a6641d8a6a6e98f48b5eb14", + "author": "csdn.net", + "keywords": "位运算,哈希表,字符串,滑动窗口,哈希函数,滚动哈希", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/122.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/122.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..6337f97aa0136f22cd2ff66a584e9704cd0154a0 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/122.exercises/solution.md" @@ -0,0 +1,97 @@ +# 重复的DNA序列 + +

所有 DNA 都由一系列缩写为 'A''C''G''T' 的核苷酸组成,例如:"ACGAATTCCG"。在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮助。

+ +

编写一个函数来找出所有目标子串,目标子串的长度为 10,且在 DNA 字符串 s 中出现次数超过一次。

+ +

 

+ +

示例 1:

+ +
+输入:s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"
+输出:["AAAAACCCCC","CCCCCAAAAA"]
+
+ +

示例 2:

+ +
+输入:s = "AAAAAAAAAAAAA"
+输出:["AAAAAAAAAA"]
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= s.length <= 105
  • +
  • s[i]'A''C''G''T'
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + vector findRepeatedDnaSequences(string s) + { + std::map word_map; + std::vector result; + for (int i = 0; i < s.length(); i++) + { + std::string word = s.substr(i, 10); + if (word_map.find(word) != word_map.end()) + { + word_map[word] += 1; + } + else + { + word_map[word] = 1; + } + } + std::map::iterator it; + for (it = word_map.begin(); it != word_map.end(); it++) + { + if (it->second > 1) + { + result.push_back(it->first); + } + } + return result; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/123.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/123.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..7fd596725b70fcf3dc9a36b01456bf7ab7487771 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/123.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-617ecf41c10541368e4d2585d3a5f77c", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/123.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/123.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..f9766c310e58bf2576b91c0ab4f72a52af0275e0 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/123.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "e5f17936775e4f7fb4aee5b522a5153e", + "author": "csdn.net", + "keywords": "数组,数学,双指针", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/123.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/123.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..e014eb116a4414292ee17ec3f661b388925c5fde --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/123.exercises/solution.md" @@ -0,0 +1,106 @@ +# 旋转数组 + +

给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。

+ +

 

+ +

进阶:

+ +
    +
  • 尽可能想出更多的解决方案,至少有三种不同的方法可以解决这个问题。
  • +
  • 你可以使用空间复杂度为 O(1) 的 原地 算法解决这个问题吗?
  • +
+ +

 

+ +

示例 1:

+ +
+输入: nums = [1,2,3,4,5,6,7], k = 3
+输出: [5,6,7,1,2,3,4]
+解释:
+向右旋转 1 步: [7,1,2,3,4,5,6]
+向右旋转 2 步: [6,7,1,2,3,4,5]
+向右旋转 3 步: [5,6,7,1,2,3,4]
+
+ +

示例 2:

+ +
+输入:nums = [-1,-100,3,99], k = 2
+输出:[3,99,-1,-100]
+解释: 
+向右旋转 1 步: [99,-1,-100,3]
+向右旋转 2 步: [3,99,-1,-100]
+ +

 

+ +

提示:

+ +
    +
  • 1 <= nums.length <= 2 * 104
  • +
  • -231 <= nums[i] <= 231 - 1
  • +
  • 0 <= k <= 105
  • +
+ +
    +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + void rotate(vector &nums, int k) + { + if (nums.empty()) + { + return; + } + int length = nums.size(); + k %= length; + while (k--) + { + int temp = nums[length - 1]; + for (int i = length - 1; i > 0; i--) + { + nums[i] = nums[i - 1]; + } + nums[0] = temp; + } + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/124.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/124.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..06a81890ededab529e8bb065e16d9e8409001e24 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/124.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-a4304e9fcd084439be358b1e58347100", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/124.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/124.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..d72ff744b483d982980027e4114217ddff9f58b9 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/124.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "91c2d236f2624016849c993a4c798f98", + "author": "csdn.net", + "keywords": "数组,动态规划", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/124.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/124.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..8262deacb9d1162f19443057873d20181b735b62 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/124.exercises/solution.md" @@ -0,0 +1,91 @@ +# 打家劫舍 + +

你是一个专业的小偷,计划偷窃沿街的房屋。每间房内都藏有一定的现金,影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警

+ +

给定一个代表每个房屋存放金额的非负整数数组,计算你 不触动警报装置的情况下 ,一夜之内能够偷窃到的最高金额。

+ +

 

+ +

示例 1:

+ +
+输入:[1,2,3,1]
+输出:4
+解释:偷窃 1 号房屋 (金额 = 1) ,然后偷窃 3 号房屋 (金额 = 3)。
+     偷窃到的最高金额 = 1 + 3 = 4 。
+ +

示例 2:

+ +
+输入:[2,7,9,3,1]
+输出:12
+解释:偷窃 1 号房屋 (金额 = 2), 偷窃 3 号房屋 (金额 = 9),接着偷窃 5 号房屋 (金额 = 1)。
+     偷窃到的最高金额 = 2 + 9 + 1 = 12 。
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= nums.length <= 100
  • +
  • 0 <= nums[i] <= 400
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int rob(vector &nums) + { + int n = nums.size(); + if (n == 0) + { + return 0; + } + + vector f(n + 1); + f[1] = nums[0]; + for (int i = 2; i <= n; ++i) + { + f[i] = max(f[i - 1], f[i - 2] + nums[i - 1]); + } + + return f[n]; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/125.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/125.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..1848bc694c72e363a499f64eb2cb5022bfd5f050 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/125.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-96ae9dfe598347d1ab79aa2750046db6", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/125.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/125.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..0ba241d463dd39584ac357413c5ab4d5cb13d3b2 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/125.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "fde5bfc5ffcc4372b5b173f3f8128454", + "author": "csdn.net", + "keywords": "树,深度优先搜索,广度优先搜索,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/125.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/125.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..a98d76cd2d552bbc35274b947249ba099accf6fd --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/125.exercises/solution.md" @@ -0,0 +1,116 @@ +# 二叉树的右视图 + +

给定一个二叉树的 根节点 root,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。

+ +

 

+ +

示例 1:

+ +

+ +
+输入: [1,2,3,null,5,null,4]
+输出: [1,3,4]
+
+ +

示例 2:

+ +
+输入: [1,null,3]
+输出: [1,3]
+
+ +

示例 3:

+ +
+输入: []
+输出: []
+
+ +

 

+ +

提示:

+ +
    +
  • 二叉树的节点个数的范围是 [0,100]
  • +
  • -100 <= Node.val <= 100 
  • +
+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + vector rightSideView(TreeNode *root) + { + + vector ret; + queue queues[2]; + + if (root != NULL) + queues[0].push(root); + + int i = 0, j = 1, tmp; + TreeNode *p; + while (!queues[0].empty() || !queues[1].empty()) + { + while (!queues[i].empty()) + { + p = queues[i].front(); + queues[i].pop(); + if (p->left) + queues[j].push(p->left); + if (p->right) + queues[j].push(p->right); + tmp = p->val; + } + + ret.push_back(tmp); + i = (i + 1) % 2; + j = (j + 1) % 2; + } + + return ret; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/126.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/126.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..1b7b29247ce4772f4bc7b084278eb318dce722b1 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/126.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-b42a7f99c1f84575bed9b796d6c8bf85", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/126.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/126.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..04240f254736ccb14ef6cb8bee2597cbad64964d --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/126.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "15ff375cf08d4b87b030c8b39867567d", + "author": "csdn.net", + "keywords": "深度优先搜索,广度优先搜索,并查集,数组,矩阵", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/126.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/126.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..a745b86d2171fea693b63451b30e3fc4a9b7fe5f --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/126.exercises/solution.md" @@ -0,0 +1,128 @@ +# 岛屿数量 + +

给你一个由 '1'(陆地)和 '0'(水)组成的的二维网格,请你计算网格中岛屿的数量。

+ +

岛屿总是被水包围,并且每座岛屿只能由水平方向和/或竖直方向上相邻的陆地连接形成。

+ +

此外,你可以假设该网格的四条边均被水包围。

+ +

 

+ +

示例 1:

+ +
+输入:grid = [
+  ["1","1","1","1","0"],
+  ["1","1","0","1","0"],
+  ["1","1","0","0","0"],
+  ["0","0","0","0","0"]
+]
+输出:1
+
+ +

示例 2:

+ +
+输入:grid = [
+  ["1","1","0","0","0"],
+  ["1","1","0","0","0"],
+  ["0","0","1","0","0"],
+  ["0","0","0","1","1"]
+]
+输出:3
+
+ +

 

+ +

提示:

+ +
    +
  • m == grid.length
  • +
  • n == grid[i].length
  • +
  • 1 <= m, n <= 300
  • +
  • grid[i][j] 的值为 '0''1'
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + void DFS(vector> &mark, vector> &grid, int x, int y) + { + mark[x][y] = 1; + static const int dx[] = {-1, 1, 0, 0}; + static const int dy[] = {0, 0, -1, 1}; + for (int i = 0; i < 4; i++) + { + int newx = dx[i] + x; + int newy = dy[i] + y; + if (newx < 0 || newx >= mark.size() || newy < 0 || newy >= mark[newx].size()) + { + continue; + } + if (mark[newx][newy] == 0 && grid[newx][newy] == '1') + { + DFS(mark, grid, newx, newy); + } + } + } + int numIslands(vector> &grid) + { + int island_num = 0; + vector> mark; + for (int i = 0; i < grid.size(); i++) + { + mark.push_back(vector()); + for (int j = 0; j < grid[i].size(); j++) + { + mark[i].push_back(0); + } + } + for (int i = 0; i < grid.size(); i++) + { + for (int j = 0; j < grid[i].size(); j++) + { + if (mark[i][j] == 0 && grid[i][j] == '1') + { + DFS(mark, grid, i, j); + island_num++; + } + } + } + return island_num; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/88.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/88.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..1f29b73d4c6497b3a49122575d924df37b47b744 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/88.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-74b08309f19b41869c4320ea58482f6c", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/88.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/88.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..3f39fa357385855eaff7e207c4ece390235940aa --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/88.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "0efe4da13111471eaabaf79555034398", + "author": "csdn.net", + "keywords": "树,广度优先搜索,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/88.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/88.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..e954232106001d2365def6b27a8da24819df5dc4 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/88.exercises/solution.md" @@ -0,0 +1,101 @@ +# 二叉树的层序遍历 + +

给你一个二叉树,请你返回其按 层序遍历 得到的节点值。 (即逐层地,从左到右访问所有节点)。

+ +

 

+ +

示例:
+二叉树:[3,9,20,null,null,15,7],

+ +
+    3
+   / \
+  9  20
+    /  \
+   15   7
+
+ +

返回其层序遍历结果:

+ +
+[
+  [3],
+  [9,20],
+  [15,7]
+]
+
+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + + +class Solution +{ +public: + vector> levelOrder(TreeNode *root) + { + if (root == NULL) + return {}; + queue queue; + TreeNode *p = root; + vector> res; + queue.push(p); + while (queue.empty() == false) + { + vector temp = {}; + int length = queue.size(); + for (int i = 0; i < length; i++) + { + p = queue.front(); + queue.pop(); + temp.push_back(p->val); + if (p->left) + queue.push(p->left); + if (p->right) + queue.push(p->right); + } + res.push_back(temp); + } + return res; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/89.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/89.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..7f893bd26982afe6513e42419e4b2bbafc2b23ae --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/89.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-60c41833285047f3b321443845611bce", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/89.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/89.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..f06972e972a8b63dbaff35676faf1501085f57ed --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/89.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "b9f1269194384877b4442ca8e7abf180", + "author": "csdn.net", + "keywords": "树,广度优先搜索,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/89.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/89.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..9d0d8c5b066fb0c4d4f518a40296b600a699449c --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/89.exercises/solution.md" @@ -0,0 +1,105 @@ +# 二叉树的锯齿形层序遍历 + +

给定一个二叉树,返回其节点值的锯齿形层序遍历。(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行)。

+ +

例如:
+给定二叉树 [3,9,20,null,null,15,7],

+ +
+    3
+   / \
+  9  20
+    /  \
+   15   7
+
+ +

返回锯齿形层序遍历如下:

+ +
+[
+  [3],
+  [20,9],
+  [15,7]
+]
+
+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + vector> zigzagLevelOrder(TreeNode *root) + { + if (!root) + return {}; + vector> res; + vector temp; + int level = 0; + queue> q; + q.push(pair(root, 0)); + while (!q.empty()) + { + TreeNode *node = q.front().first; + level = q.front().second; + q.pop(); + if (res.size() < level) + { + if (level % 2 == 0) + reverse(temp.begin(), temp.end()); + res.push_back(temp); + temp.clear(); + } + temp.push_back(node->val); + if (node->left) + q.push(pair(node->left, level + 1)); + if (node->right) + q.push(pair(node->right, level + 1)); + } + if (level % 2 != 0) + reverse(temp.begin(), temp.end()); + res.push_back(temp); + return res; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/90.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/90.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..f5ff2b0be57139a847d788d3f36dae80bf406862 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/90.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-dff4c4e10e6f42a1ac201dd4d0ff8664", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/90.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/90.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..c86acc0ae09ab1e972186fa6bcb2a67d9c2086cd --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/90.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "ba75cf15fbae4173ae855d7975a09c08", + "author": "csdn.net", + "keywords": "树,数组,哈希表,分治,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/90.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/90.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..5469faf018853f2bdebfddcec127ae5a14c83dab --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/90.exercises/solution.md" @@ -0,0 +1,108 @@ +# 从前序与中序遍历序列构造二叉树 + +

给定一棵树的前序遍历 preorder 与中序遍历  inorder。请构造二叉树并返回其根节点。

+ +

 

+ +

示例 1:

+ +
+Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]
+Output: [3,9,20,null,null,15,7]
+
+ +

示例 2:

+ +
+Input: preorder = [-1], inorder = [-1]
+Output: [-1]
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= preorder.length <= 3000
  • +
  • inorder.length == preorder.length
  • +
  • -3000 <= preorder[i], inorder[i] <= 3000
  • +
  • preorder 和 inorder 均无重复元素
  • +
  • inorder 均出现在 preorder
  • +
  • preorder 保证为二叉树的前序遍历序列
  • +
  • inorder 保证为二叉树的中序遍历序列
  • +
+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +private: + unordered_map inMap; + +public: + TreeNode *myBuildTree(vector &preorder, int preStart, int preEnd, vector &inorder, int inStart, int inEnd) + { + if (preStart > preEnd) + return nullptr; + + TreeNode *root = new TreeNode(preorder[preStart]); + + int inRoot = inMap[preorder[preStart]]; + int numsLeft = inRoot - inStart; + + root->left = myBuildTree(preorder, preStart + 1, preStart + numsLeft, inorder, inStart, inRoot - 1); + root->right = myBuildTree(preorder, preStart + numsLeft + 1, preEnd, inorder, inRoot + 1, inEnd); + return root; + } + + TreeNode *buildTree(vector &preorder, vector &inorder) + { + int n = preorder.size(); + for (int i = 0; i < n; i++) + { + inMap[inorder[i]] = i; + } + return myBuildTree(preorder, 0, n - 1, inorder, 0, n - 1); + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/91.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/91.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..ccf7f2b13b04767c91bbf33e9e18dba601092aba --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/91.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-b8f6aa5c87444972987d7e7a1e52a22c", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/91.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/91.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..bf703fd4980885e8997a3308c0144f857da8e3dc --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/91.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "114fd3f88e654e509ae581d5b5283b34", + "author": "csdn.net", + "keywords": "树,数组,哈希表,分治,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/91.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/91.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..9a6d528ea366b43446eb596571ed8fe60b28ac95 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/91.exercises/solution.md" @@ -0,0 +1,97 @@ +# 从中序与后序遍历序列构造二叉树 + +

根据一棵树的中序遍历与后序遍历构造二叉树。

+ +

注意:
+你可以假设树中没有重复的元素。

+ +

例如,给出

+ +
中序遍历 inorder = [9,3,15,20,7]
+后序遍历 postorder = [9,15,7,20,3]
+ +

返回如下的二叉树:

+ +
    3
+   / \
+  9  20
+    /  \
+   15   7
+
+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + TreeNode *buildTree(vector &inorder, vector &postorder) + { + if (0 == inorder.size() || 0 == postorder.size()) + { + return NULL; + } + return build(inorder, 0, inorder.size() - 1, postorder, 0, postorder.size() - 1); + } + + TreeNode *build(vector &inorder, int i1, int i2, vector &postorder, int p1, int p2) + { + TreeNode *root = new TreeNode(postorder[p2]); + int i = i1; + while (i <= i2 && postorder[p2] != inorder[i]) + { + i++; + } + int left = i - i1; + int right = i2 - i; + if (left > 0) + { + root->left = build(inorder, i1, i - 1, postorder, p1, p1 + left - 1); + } + if (right > 0) + { + root->right = build(inorder, i + 1, i2, postorder, p1 + left, p2 - 1); + } + return root; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/92.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/92.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..689b2f43813d423f0f4157d0ef68baa64ae05db2 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/92.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-d26621ba92b24aeeb003c86d47d36ad6", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/92.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/92.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..06c5c22621cc568cab27c8560fe14da52cde79a7 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/92.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "3d8e9a5ee3b6439d92b567b667c50864", + "author": "csdn.net", + "keywords": "树,广度优先搜索,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/92.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/92.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..80df184b406de92269f34efb7d7829a5236ec2ec --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/92.exercises/solution.md" @@ -0,0 +1,99 @@ +# 二叉树的层序遍历 II + +

给定一个二叉树,返回其节点值自底向上的层序遍历。 (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历)

+ +

例如:
+给定二叉树 [3,9,20,null,null,15,7],

+ +
+    3
+   / \
+  9  20
+    /  \
+   15   7
+
+ +

返回其自底向上的层序遍历为:

+ +
+[
+  [15,7],
+  [9,20],
+  [3]
+]
+
+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + + +class Solution +{ +public: + vector> levelOrderBottom(TreeNode *root) + { + + vector> res; + if (root == NULL) + return res; + queue q; + q.push(root); + while (!q.empty()) + { + vector oneLevel; + int size = q.size(); + for (int i = 0; i < size; i++) + { + TreeNode *node = q.front(); + q.pop(); + oneLevel.push_back(node->val); + if (node->left) + q.push(node->left); + if (node->right) + q.push(node->right); + } + res.insert(res.begin(), oneLevel); + } + return res; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/93.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/93.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..9c85b8a4b109e0c0cd0e2a16c18a2a42a980f842 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/93.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-935af29ed8e5492cbb0712c8b1d0c653", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/93.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/93.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..3a2758fa509ef60408277523aa1f6f2cf69c998c --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/93.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "8532653591304c138feba57d32124c1c", + "author": "csdn.net", + "keywords": "树,二叉搜索树,链表,分治,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/93.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/93.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..ebdba906174f4a9f9a9aa162af192a6bab8934da --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/93.exercises/solution.md" @@ -0,0 +1,95 @@ +# 有序链表转换二叉搜索树 + +

给定一个单链表,其中的元素按升序排序,将其转换为高度平衡的二叉搜索树。

+ +

本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1。

+ +

示例:

+ +
给定的有序链表: [-10, -3, 0, 5, 9],
+
+一个可能的答案是:[0, -3, 9, -10, null, 5], 它可以表示下面这个高度平衡二叉搜索树:
+
+      0
+     / \
+   -3   9
+   /   /
+ -10  5
+
+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + vector nums; + TreeNode *create(int low, int high) + { + if (low > high) + return NULL; + int mid = (low + high) / 2; + auto root = new TreeNode(nums[mid]); + root->left = create(low, mid - 1); + root->right = create(mid + 1, high); + return root; + } + TreeNode *sortedListToBST(ListNode *head) + { + while (head) + { + nums.push_back(head->val); + head = head->next; + } + + return create(0, nums.size() - 1); + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/94.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/94.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..9a0acacba15a66e3f7ef446957ac370c03ab466a --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/94.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-d202c192ccde42a8a79bb7439fc7bf10", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/94.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/94.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..65ed7d126310408cfb695a82ed21020429d5b44e --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/94.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "f891f16e32ea433e9dc188d9ea0d65ee", + "author": "csdn.net", + "keywords": "树,深度优先搜索,回溯,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/94.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/94.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..c53bd9dc0e0f0c954a78940c10bd8c01f057b012 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/94.exercises/solution.md" @@ -0,0 +1,128 @@ +# 路径总和 II + +

给你二叉树的根节点 root 和一个整数目标和 targetSum ,找出所有 从根节点到叶子节点 路径总和等于给定目标和的路径。

+ +

叶子节点 是指没有子节点的节点。

+ +
+
+

 

+ +

示例 1:

+ +
+输入:root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22
+输出:[[5,4,11,2],[5,8,4,5]]
+
+ +

示例 2:

+ +
+输入:root = [1,2,3], targetSum = 5
+输出:[]
+
+ +

示例 3:

+ +
+输入:root = [1,2], targetSum = 0
+输出:[]
+
+ +

 

+ +

提示:

+ +
    +
  • 树中节点总数在范围 [0, 5000]
  • +
  • -1000 <= Node.val <= 1000
  • +
  • -1000 <= targetSum <= 1000
  • +
+
+
+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + vector> pathSum(TreeNode *root, int sum) + { + vector> res; + vector track; + backTrack(root, res, track, sum); + return res; + } + + void backTrack(TreeNode *root, vector> &res, vector track, int sum) + { + + if (!root) + { + return; + } + if (!root->left && !root->right) + { + sum -= root->val; + track.push_back(root->val); + if (sum == 0) + { + res.push_back(track); + } + track.pop_back(); + sum += root->val; + return; + } + + sum -= root->val; + track.push_back(root->val); + + backTrack(root->left, res, track, sum); + backTrack(root->right, res, track, sum); + + track.pop_back(); + sum += root->val; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/95.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/95.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..85850d525377f24d9ebf3a114fbc5b2360fb266c --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/95.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-2728da0a5a584b3b8eee17473182c2e2", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/95.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/95.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..e988953e06d3aed896fcb627e3f133e500a0019c --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/95.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "fd0fc75e932545d8ba6c3ecc71bebf22", + "author": "csdn.net", + "keywords": "栈,树,深度优先搜索,链表,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/95.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/95.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..dbe68d297b81c7133be5f5201b97783e8a6ca2a8 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/95.exercises/solution.md" @@ -0,0 +1,113 @@ +# 二叉树展开为链表 + +

给你二叉树的根结点 root ,请你将它展开为一个单链表:

+ +
    +
  • 展开后的单链表应该同样使用 TreeNode ,其中 right 子指针指向链表中下一个结点,而左子指针始终为 null
  • +
  • 展开后的单链表应该与二叉树 先序遍历 顺序相同。
  • +
+ +

 

+ +

示例 1:

+ +
+输入:root = [1,2,5,3,4,null,6]
+输出:[1,null,2,null,3,null,4,null,5,null,6]
+
+ +

示例 2:

+ +
+输入:root = []
+输出:[]
+
+ +

示例 3:

+ +
+输入:root = [0]
+输出:[0]
+
+ +

 

+ +

提示:

+ +
    +
  • 树中结点数在范围 [0, 2000]
  • +
  • -100 <= Node.val <= 100
  • +
+ +

 

+ +

进阶:你可以使用原地算法(O(1) 额外空间)展开这棵树吗?

+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + void rconnect(TreeNode *&node, TreeNode *pmove) + { + if (pmove == nullptr) + return; + node->right = new TreeNode(pmove->val); + node->left = nullptr; + node = node->right; + rconnect(node, pmove->left); + rconnect(node, pmove->right); + } + void flatten(TreeNode *root) + { + if (root == nullptr) + return; + TreeNode *head = new TreeNode(); + TreeNode *newroot = head; + rconnect(head, root); + newroot = newroot->right->right; + root->right = newroot; + root->left = nullptr; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/96.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/96.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..7363f606b4e64b4113714c6266df32be2fe74de5 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/96.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-4e7bac103be94ad1b0b11a1ee6256987", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/96.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/96.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..8bc0d72fd559967b6ad2cd82ff40659c800f4878 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/96.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "8a772d0bda8142c3bdddb1b4d18cc62a", + "author": "csdn.net", + "keywords": "树,深度优先搜索,广度优先搜索,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/96.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/96.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..403d34145c1386c63bda2e345649675a35fee8c6 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/96.exercises/solution.md" @@ -0,0 +1,131 @@ +# 填充每个节点的下一个右侧节点指针 + +

给定一个 完美二叉树 ,其所有叶子节点都在同一层,每个父节点都有两个子节点。二叉树定义如下:

+ +
+struct Node {
+  int val;
+  Node *left;
+  Node *right;
+  Node *next;
+}
+ +

填充它的每个 next 指针,让这个指针指向其下一个右侧节点。如果找不到下一个右侧节点,则将 next 指针设置为 NULL

+ +

初始状态下,所有 next 指针都被设置为 NULL

+ +

 

+ +

进阶:

+ +
    +
  • 你只能使用常量级额外空间。
  • +
  • 使用递归解题也符合要求,本题中递归程序占用的栈空间不算做额外的空间复杂度。
  • +
+ +

 

+ +

示例:

+ +

+ +
+输入:root = [1,2,3,4,5,6,7]
+输出:[1,#,2,3,#,4,5,6,7,#]
+解释:给定二叉树如图 A 所示,你的函数应该填充它的每个 next 指针,以指向其下一个右侧节点,如图 B 所示。序列化的输出按层序遍历排列,同一层节点由 next 指针连接,'#' 标志着每一层的结束。
+
+ +

 

+ +

提示:

+ +
    +
  • 树中节点的数量少于 4096
  • +
  • -1000 <= node.val <= 1000
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Node +{ +public: + int val; + Node *left; + Node *right; + Node *next; + Node() : val(0), left(NULL), right(NULL), next(NULL) {} + Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {} + Node(int _val, Node *_left, Node *_right, Node *_next) + : val(_val), left(_left), right(_right), next(_next) {} +}; + +class Solution +{ +public: + Node *connect(Node *root) + { + if (!root) + return nullptr; + + root->next = nullptr; + connect_helper(root); + + return root; + } + +private: + void connect_helper(Node *pNode) + { + if (!pNode) + return; + + if (pNode->left == nullptr) + return; + + pNode->left->next = pNode->right; + + if (pNode->right == nullptr) + return; + + if (pNode->next != nullptr) + pNode->right->next = pNode->next->left; + else + pNode->right->next = nullptr; + + connect_helper(pNode->left); + connect_helper(pNode->right); + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/97.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/97.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..428de3e3a8cad005c2806a62d2806b2d9db8112c --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/97.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-acbff7e537ff4e00aafefb58ac6f1bd8", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/97.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/97.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..49e6602862a78b77b996817033ff5fff2ad5c2a4 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/97.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "fd74d5ca92e349568bf63c4e9ebdeed9", + "author": "csdn.net", + "keywords": "树,深度优先搜索,广度优先搜索,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/97.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/97.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..d37f6b23bbfc07098e080ccad607cf2ca03127ad --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/97.exercises/solution.md" @@ -0,0 +1,130 @@ +# 填充每个节点的下一个右侧节点指针 II + +

给定一个二叉树

+ +
+struct Node {
+  int val;
+  Node *left;
+  Node *right;
+  Node *next;
+}
+ +

填充它的每个 next 指针,让这个指针指向其下一个右侧节点。如果找不到下一个右侧节点,则将 next 指针设置为 NULL

+ +

初始状态下,所有 next 指针都被设置为 NULL

+ +

 

+ +

进阶:

+ +
    +
  • 你只能使用常量级额外空间。
  • +
  • 使用递归解题也符合要求,本题中递归程序占用的栈空间不算做额外的空间复杂度。
  • +
+ +

 

+ +

示例:

+ +

+ +
+输入:root = [1,2,3,4,5,null,7]
+输出:[1,#,2,3,#,4,5,7,#]
+解释:给定二叉树如图 A 所示,你的函数应该填充它的每个 next 指针,以指向其下一个右侧节点,如图 B 所示。序列化输出按层序遍历顺序(由 next 指针连接),'#' 表示每层的末尾。
+ +

 

+ +

提示:

+ +
    +
  • 树中的节点数小于 6000
  • +
  • -100 <= node.val <= 100
  • +
+ +

 

+ +
    +
+ + +## template + +```cpp +#include +using namespace std; + +class Node +{ +public: + int val; + Node *left; + Node *right; + Node *next; + Node() : val(0), left(NULL), right(NULL), next(NULL) {} + Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {} + Node(int _val, Node *_left, Node *_right, Node *_next) + : val(_val), left(_left), right(_right), next(_next) {} +}; + +class Solution +{ +public: + Node *connect(Node *root) + { + if (!root) + return NULL; + Node *p = root->next; + while (p) + { + if (p->left) + { + p = p->left; + break; + } + if (p->right) + { + p = p->right; + break; + } + p = p->next; + } + if (root->right) + root->right->next = p; + if (root->left) + root->left->next = root->right ? root->right : p; + connect(root->right); + connect(root->left); + return root; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/98.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/98.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..ba6cebd959cde9bfb306ec4cb35921b2a9af8209 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/98.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-b84e0ad3b5c8484ab8dbb922eeead085", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/98.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/98.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..e733cba75a83a4fd3e22e03b71c4f8fff9fb6b86 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/98.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "383ae4c542d449439fc15dd853dbf9cd", + "author": "csdn.net", + "keywords": "数组,动态规划", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/98.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/98.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..6baaa6197f8f41c4588af014979945381b420ce1 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/98.exercises/solution.md" @@ -0,0 +1,120 @@ +# 三角形最小路径和 + +

给定一个三角形 triangle ,找出自顶向下的最小路径和。

+ +

每一步只能移动到下一行中相邻的结点上。相邻的结点 在这里指的是 下标上一层结点下标 相同或者等于 上一层结点下标 + 1 的两个结点。也就是说,如果正位于当前行的下标 i ,那么下一步可以移动到下一行的下标 ii + 1

+ +

 

+ +

示例 1:

+ +
+输入:triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]
+输出:11
+解释:如下面简图所示:
+   2
+  3 4
+ 6 5 7
+4 1 8 3
+自顶向下的最小路径和为 11(即,2 + 3 + 5 + 1 = 11)。
+
+ +

示例 2:

+ +
+输入:triangle = [[-10]]
+输出:-10
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= triangle.length <= 200
  • +
  • triangle[0].length == 1
  • +
  • triangle[i].length == triangle[i - 1].length + 1
  • +
  • -104 <= triangle[i][j] <= 104
  • +
+ +

 

+ +

进阶:

+ +
    +
  • 你可以只使用 O(n) 的额外空间(n 为三角形的总行数)来解决这个问题吗?
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int minimumTotal(vector> &triangle) + { + int n = triangle.size(); + if (n == 0) + return 0; + if (n == 1) + return triangle[0][0]; + vector> info(n, vector(n, 0)); + info[0][0] = triangle[0][0]; + for (int i = 1; i < n; ++i) + { + for (int j = 0; j <= i; ++j) + { + if (j == 0) + info[i][j] = triangle[i][j] + info[i - 1][j]; + else if (j == i) + info[i][j] = triangle[i][j] + info[i - 1][j - 1]; + else + { + int temp = info[i - 1][j] > info[i - 1][j - 1] ? info[i - 1][j - 1] : info[i - 1][j]; + info[i][j] = temp + triangle[i][j]; + } + } + } + int res = info[n - 1][0]; + for (int i = 0; i < n; ++i) + { + if (info[n - 1][i] < res) + { + res = info[n - 1][i]; + } + } + return res; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/99.exercises/config.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/99.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..16ffcf0fc9ba32d1f2068ab04aa3a3f324d3d417 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/99.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-abe1e612615b4a0cb30c4d43d8317bcf", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/99.exercises/solution.json" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/99.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..bfb1ba870e69927a44b531707aa3626a8ca08144 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/99.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "51ccf4e117df4625be67d2c9ff6bab72", + "author": "csdn.net", + "keywords": "并查集,数组,哈希表", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/2.dailycode\344\270\255\351\230\266/1.cpp/99.exercises/solution.md" "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/99.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..fca772aec430ce905ff6fb4ea8286eaa83558cd5 --- /dev/null +++ "b/data/2.dailycode\344\270\255\351\230\266/1.cpp/99.exercises/solution.md" @@ -0,0 +1,101 @@ +# 最长连续序列 + +

给定一个未排序的整数数组 nums ,找出数字连续的最长序列(不要求序列元素在原数组中连续)的长度。

+ +

请你设计并实现时间复杂度为 O(n) 的算法解决此问题。

+ +

 

+ +

示例 1:

+ +
+输入:nums = [100,4,200,1,3,2]
+输出:4
+解释:最长数字连续序列是 [1, 2, 3, 4]。它的长度为 4。
+ +

示例 2:

+ +
+输入:nums = [0,3,7,2,5,8,4,6,0,1]
+输出:9
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= nums.length <= 105
  • +
  • -109 <= nums[i] <= 109
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int longestConsecutive(vector &nums) + { + unordered_set s; + for (auto v : nums) + s.insert(v); + int res = 0; + for (auto v : nums) + { + if (s.find(v) != s.end()) + { + s.erase(v); + int temp = 1; + int cur = v; + while (s.find(cur - 1) != s.end()) + { + cur--; + s.erase(cur); + } + temp += v - cur; + cur = v; + while (s.find(cur + 1) != s.end()) + { + cur++; + s.erase(cur); + } + temp += cur - v; + res = max(res, temp); + } + } + return res; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/41.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/41.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..fb893651364b007a0a5077e608f7c61847ad7f38 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/41.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-20b092dea834439fb605c1749d6e268b", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/41.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/41.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..c41a54d5d64dfccdae970d470eccd8325b5ee2a1 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/41.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "4175e229f9cb4ec297b994f018f5bf95", + "author": "csdn.net", + "keywords": "字符串,动态规划", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/41.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/41.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..c877942b2aebee548a1ceff40bc5c4a0b22ec298 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/41.exercises/solution.md" @@ -0,0 +1,99 @@ +# 不同的子序列 + +

给定一个字符串 s 和一个字符串 t ,计算在 s 的子序列中 t 出现的个数。

+ +

字符串的一个 子序列 是指,通过删除一些(也可以不删除)字符且不干扰剩余字符相对位置所组成的新字符串。(例如,"ACE" 是 "ABCDE" 的一个子序列,而 "AEC" 不是)

+ +

题目数据保证答案符合 32 位带符号整数范围。

+ +

 

+ +

示例 1:

+ +
+输入:s = "rabbbit", t = "rabbit"
+输出3
+解释:
+如下图所示, 有 3 种可以从 s 中得到 "rabbit" 的方案。
+rabbbit
+rabbbit
+rabbbit
+ +

示例 2:

+ +
+输入:s = "babgbag", t = "bag"
+输出5
+解释:
+如下图所示, 有 5 种可以从 s 中得到 "bag" 的方案。 
+babgbag
+babgbag
+babgbag
+babgbag
+babgbag
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= s.length, t.length <= 1000
  • +
  • st 由英文字母组成
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int numDistinct(string s, string t) + { + long dp[t.size() + 1][s.size() + 1]; + for (int i = 0; i <= s.size(); ++i) + dp[0][i] = 1; + for (int i = 1; i <= t.size(); ++i) + dp[i][0] = 0; + for (int i = 1; i <= t.size(); ++i) + { + for (int j = 1; j <= s.size(); ++j) + { + dp[i][j] = dp[i][j - 1] + (t[i - 1] == s[j - 1] ? dp[i - 1][j - 1] : 0); + } + } + return dp[t.size()][s.size()]; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/42.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/42.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..12e788ab2e6b8e0e2857644d228a3d22147b2e64 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/42.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-b21a1bcfe07c466d894abf1624a2e27b", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/42.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/42.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..9ca9cb4ea8e52aa26e63fa70616b04b0496a52ab --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/42.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "14750c7919bf4d9cb1cc1b9dc589acd9", + "author": "csdn.net", + "keywords": "数组,动态规划", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/42.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/42.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..e779d2fe09c233e70936fbb3e3fc3257ce5a680b --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/42.exercises/solution.md" @@ -0,0 +1,117 @@ +# 买卖股票的最佳时机 III + +

给定一个数组,它的第 i 个元素是一支给定的股票在第 i 天的价格。

+ +

设计一个算法来计算你所能获取的最大利润。你最多可以完成 两笔 交易。

+ +

注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。

+ +

 

+ +

示例 1:

+ +
+输入:prices = [3,3,5,0,0,3,1,4]
+输出:6
+解释:在第 4 天(股票价格 = 0)的时候买入,在第 6 天(股票价格 = 3)的时候卖出,这笔交易所能获得利润 = 3-0 = 3 。
+     随后,在第 7 天(股票价格 = 1)的时候买入,在第 8 天 (股票价格 = 4)的时候卖出,这笔交易所能获得利润 = 4-1 = 3 。
+ +

示例 2:

+ +
+输入:prices = [1,2,3,4,5]
+输出:4
+解释:在第 1 天(股票价格 = 1)的时候买入,在第 5 天 (股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。   
+     注意你不能在第 1 天和第 2 天接连购买股票,之后再将它们卖出。   
+     因为这样属于同时参与了多笔交易,你必须在再次购买前出售掉之前的股票。
+
+ +

示例 3:

+ +
+输入:prices = [7,6,4,3,1] 
+输出:0 
+解释:在这个情况下, 没有交易完成, 所以最大利润为 0。
+ +

示例 4:

+ +
+输入:prices = [1]
+输出:0
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= prices.length <= 105
  • +
  • 0 <= prices[i] <= 105
  • +
+ + +## template + +```cpp + +class Solution +{ +public: + int maxProfit(vector &prices) + { + int length = prices.size(); + if (length < 2) + { + return 0; + } + vector former(length, 0); + vector later(length, 0); + int curMin = prices[0]; + int curProfit = 0; + for (int i = 1; i < length; i++) + { + curProfit = max(curProfit, prices[i] - curMin); + curMin = min(curMin, prices[i]); + former[i] = curProfit; + } + int curMax = prices[length - 1]; + curProfit = 0; + for (int i = length - 2; i >= 0; i--) + { + curProfit = max(curProfit, curMax - prices[i]); + curMax = max(curMax, prices[i]); + later[i] = curProfit; + } + int maxProfit = 0; + for (int i = 0; i < length; i++) + maxProfit = max(maxProfit, former[i] + later[i]); + return maxProfit; + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/43.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/43.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..7d26412d416f474a5983e012ae3a03c20b4cddf2 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/43.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-d58de695f661474f8a2f72bf151c32f4", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/43.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/43.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..471c0d73dd4124295f9c4ae55fb46a6a7378c79a --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/43.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "9cb85eede3984b70b08147e8b4525294", + "author": "csdn.net", + "keywords": "树,深度优先搜索,动态规划,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/43.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/43.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..6076c4909f0923b8e9be7f302e1feb106c908c15 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/43.exercises/solution.md" @@ -0,0 +1,130 @@ +# 二叉树中的最大路径和 + +

路径 被定义为一条从树中任意节点出发,沿父节点-子节点连接,达到任意节点的序列。同一个节点在一条路径序列中 至多出现一次 。该路径 至少包含一个 节点,且不一定经过根节点。

+ +

路径和 是路径中各节点值的总和。

+ +

给你一个二叉树的根节点 root ,返回其 最大路径和

+ +

 

+ +

示例 1:

+ +
+输入:root = [1,2,3]
+输出:6
+解释:最优路径是 2 -> 1 -> 3 ,路径和为 2 + 1 + 3 = 6
+ +

示例 2:

+ +
+输入:root = [-10,9,20,null,null,15,7]
+输出:42
+解释:最优路径是 15 -> 20 -> 7 ,路径和为 15 + 20 + 7 = 42
+
+ +

 

+ +

提示:

+ +
    +
  • 树中节点数目范围是 [1, 3 * 104]
  • +
  • -1000 <= Node.val <= 1000
  • +
+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + int maxPathSum(TreeNode *root) + { + if (!root) + return 0; + vector ss; + unordered_map val; + ss.push_back(root); + int len = 1; + queue q{{root}}; + while (!q.empty()) + { + TreeNode *t = q.front(); + q.pop(); + cout << t->val << endl; + if (t->left) + { + len++; + q.push(t->left); + ss.push_back(t->left); + } + if (t->right) + { + len++; + q.push(t->right); + ss.push_back(t->right); + } + } + + int res = INT_MIN; + + while (len > 0) + { + TreeNode *node = ss[--len]; + int ps = node->val; + int s = ps; + + int ls = max(0, val[node->left]); + int rs = max(0, val[node->right]); + + ps += max(ls, rs); + val[node] = ps; + + s += ls + rs; + res = max(s, res); + } + + return res; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/44.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/44.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..f57f5fe98a42b3da7d0818d0302238861c2c6310 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/44.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-d92de43caa3540a4b5aa693d35035468", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/44.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/44.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..5b6ef48064b90e1878044914723ce85509099626 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/44.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "bc43d567d92b494b84197834566161dd", + "author": "csdn.net", + "keywords": "广度优先搜索,哈希表,字符串,回溯", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/44.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/44.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..f3303bb6c8396e4549091115edc3bc6ceb65eda0 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/44.exercises/solution.md" @@ -0,0 +1,153 @@ +# 单词接龙 II + +

按字典 wordList 完成从单词 beginWord 到单词 endWord 转化,一个表示此过程的 转换序列 是形式上像 beginWord -> s1 -> s2 -> ... -> sk 这样的单词序列,并满足:

+ +
+
+
    +
  • 每对相邻的单词之间仅有单个字母不同。
  • +
  • 转换过程中的每个单词 si1 <= i <= k)必须是字典 wordList 中的单词。注意,beginWord 不必是字典 wordList 中的单词。
  • +
  • sk == endWord
  • +
+ +

给你两个单词 beginWordendWord ,以及一个字典 wordList 。请你找出并返回所有从 beginWordendWord最短转换序列 ,如果不存在这样的转换序列,返回一个空列表。每个序列都应该以单词列表 [beginWord, s1, s2, ..., sk] 的形式返回。

+ +

 

+ +

示例 1:

+ +
+输入:beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]
+输出:[["hit","hot","dot","dog","cog"],["hit","hot","lot","log","cog"]]
+解释:存在 2 种最短的转换序列:
+"hit" -> "hot" -> "dot" -> "dog" -> "cog"
+"hit" -> "hot" -> "lot" -> "log" -> "cog"
+
+ +

示例 2:

+ +
+输入:beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"]
+输出:[]
+解释:endWord "cog" 不在字典 wordList 中,所以不存在符合要求的转换序列。
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= beginWord.length <= 7
  • +
  • endWord.length == beginWord.length
  • +
  • 1 <= wordList.length <= 5000
  • +
  • wordList[i].length == beginWord.length
  • +
  • beginWordendWordwordList[i] 由小写英文字母组成
  • +
  • beginWord != endWord
  • +
  • wordList 中的所有单词 互不相同
  • +
+
+
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + bool differ_one(string &s, string &t) + { + int n = 0; + for (int i = 0; i < s.size(); ++i) + if ((n += s[i] != t[i]) > 1) + return false; + return n == 1; + } + vector> fa; + vector tmp; + vector> ans; + void dfs(int index, vector &wordList) + { + if (fa[index].empty()) + { + reverse(tmp.begin(), tmp.end()); + ans.push_back(tmp); + reverse(tmp.begin(), tmp.end()); + } + for (auto &x : fa[index]) + { + tmp.push_back(wordList[x]); + dfs(x, wordList); + tmp.pop_back(); + } + } + vector> findLadders(string beginWord, string endWord, vector &wordList) + { + + int b = -1, e = -1, x; + for (int i = 0; i < wordList.size(); ++i) + { + if (wordList[i] == beginWord) + b = i; + if (wordList[i] == endWord) + e = i; + } + if (e == -1) + return ans; + if (b == -1) + wordList.push_back(beginWord), b = wordList.size() - 1; + queue que; + fa.assign(wordList.size(), vector()); + vector index(wordList.size(), 0); + que.push(b), index[b] = 1; + while (!que.empty()) + { + x = que.front(), que.pop(); + if (index[e] && index[x] >= index[e]) + break; + for (int i = 0; i < wordList.size(); ++i) + if ((index[i] == 0 || index[x] + 1 == index[i]) && differ_one(wordList[x], wordList[i])) + if (index[i] == 0) + index[i] = index[x] + 1, que.push(i), fa[i].push_back(x); + else + fa[i].push_back(x); + } + if (index[e] == 0) + return ans; + tmp.push_back(endWord); + dfs(e, wordList); + tmp.pop_back(); + return ans; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/45.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/45.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..7302e5533e5c6e0ee18d80a218633ee88762ef6f --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/45.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-98daf8a40cf94f16b451b22387358559", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/45.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/45.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..aedef69a9a9246f0420bc7c2a4478c4849e79b89 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/45.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "d8fd443f1d594cca97e0cbba610a3249", + "author": "csdn.net", + "keywords": "广度优先搜索,哈希表,字符串", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/45.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/45.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..f4cb1a5b54badf098fbeb5993825a56e8fa28bf6 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/45.exercises/solution.md" @@ -0,0 +1,129 @@ +# 单词接龙 + +

字典 wordList 中从单词 beginWord endWord转换序列 是一个按下述规格形成的序列:

+ +
    +
  • 序列中第一个单词是 beginWord
  • +
  • 序列中最后一个单词是 endWord
  • +
  • 每次转换只能改变一个字母。
  • +
  • 转换过程中的中间单词必须是字典 wordList 中的单词。
  • +
+ +

给你两个单词 beginWord endWord 和一个字典 wordList ,找到从 beginWord 到 endWord最短转换序列 中的 单词数目 。如果不存在这样的转换序列,返回 0。

+  + +

示例 1:

+ +
+输入:beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]
+输出:5
+解释:一个最短转换序列是 "hit" -> "hot" -> "dot" -> "dog" -> "cog", 返回它的长度 5。
+
+ +

示例 2:

+ +
+输入:beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log"]
+输出:0
+解释:endWord "cog" 不在字典中,所以无法进行转换。
+ +

 

+ +

提示:

+ +
    +
  • 1 <= beginWord.length <= 10
  • +
  • endWord.length == beginWord.length
  • +
  • 1 <= wordList.length <= 5000
  • +
  • wordList[i].length == beginWord.length
  • +
  • beginWordendWordwordList[i] 由小写英文字母组成
  • +
  • beginWord != endWord
  • +
  • wordList 中的所有字符串 互不相同
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int ladderLength(string beginWord, string endWord, vector &wordList) + { + + unordered_set dict(wordList.begin(), wordList.end()); + if (dict.find(endWord) == dict.end()) + return 0; + + queue> q; + q.push(make_pair(beginWord, 1)); + + string tmp; + int step; + + while (!q.empty()) + { + auto p = q.front(); + + if (p.first == endWord) + return p.second; + tmp = p.first; + step = p.second; + q.pop(); + + char old_ch; + for (int i = 0; i < tmp.size(); ++i) + { + old_ch = tmp[i]; + + for (char c = 'a'; c <= 'z'; ++c) + { + + if (c == old_ch) + continue; + tmp[i] = c; + + if (dict.find(tmp) != dict.end()) + { + q.push(make_pair(tmp, step + 1)); + dict.erase(tmp); + } + } + tmp[i] = old_ch; + } + } + return 0; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/46.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/46.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..fe8dbc51a753d676e804670afaad84d959f36545 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/46.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-623ee98952304b7e9b919c3d7e146a19", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/46.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/46.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..a5e02f0ef5634219eb3c405f1b1024f93c5335a1 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/46.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "a8246082dcfb4ea5afea0cf24bb12dc2", + "author": "csdn.net", + "keywords": "字符串,动态规划", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/46.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/46.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..0f6086a2a122d728fb448773d31c347982eadb92 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/46.exercises/solution.md" @@ -0,0 +1,113 @@ +# 分割回文串 II + +

给你一个字符串 s,请你将 s 分割成一些子串,使每个子串都是回文。

+ +

返回符合要求的 最少分割次数

+ +
+
+

 

+ +

示例 1:

+ +
+输入:s = "aab"
+输出:1
+解释:只需一次分割就可将 s 分割成 ["aa","b"] 这样两个回文子串。
+
+ +

示例 2:

+ +
+输入:s = "a"
+输出:0
+
+ +

示例 3:

+ +
+输入:s = "ab"
+输出:1
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= s.length <= 2000
  • +
  • s 仅由小写英文字母组成
  • +
+
+
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int minCut(string s) + { + + const int N = s.size(); + if (N <= 1) + return 0; + + int i, j; + + bool isPalin[N][N]; + + fill_n(&isPalin[0][0], N * N, false); + + int minCuts[N + 1]; + for (i = 0; i <= N; ++i) + minCuts[i] = i - 1; + + for (j = 1; j < N; ++j) + { + for (i = j; i >= 0; --i) + { + + if ((s[i] == s[j]) && ((j - i < 2) || isPalin[i + 1][j - 1])) + { + isPalin[i][j] = true; + minCuts[j + 1] = min(minCuts[j + 1], 1 + minCuts[i]); + } + } + } + return minCuts[N]; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/47.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/47.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..4a2e56b81dc0e3d468dcaad5724392623610d083 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/47.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-37990a05873740ab861f20f4e78be70b", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/47.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/47.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..2f954a44f0603028e3f57581da103f54096bf821 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/47.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "11ebd5d979fb4925941083ff52136c4e", + "author": "csdn.net", + "keywords": "贪心,数组", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/47.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/47.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..e236f6a3400f6a729066ccaa099907bf3e166f9c --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/47.exercises/solution.md" @@ -0,0 +1,93 @@ +# 分发糖果 + +

老师想给孩子们分发糖果,有 N 个孩子站成了一条直线,老师会根据每个孩子的表现,预先给他们评分。

+ +

你需要按照以下要求,帮助老师给这些孩子分发糖果:

+ +
    +
  • 每个孩子至少分配到 1 个糖果。
  • +
  • 评分更高的孩子必须比他两侧的邻位孩子获得更多的糖果。
  • +
+ +

那么这样下来,老师至少需要准备多少颗糖果呢?

+ +

 

+ +

示例 1:

+ +
+输入:[1,0,2]
+输出:5
+解释:你可以分别给这三个孩子分发 2、1、2 颗糖果。
+
+ +

示例 2:

+ +
+输入:[1,2,2]
+输出:4
+解释:你可以分别给这三个孩子分发 1、2、1 颗糖果。
+     第三个孩子只得到 1 颗糖果,这已满足上述两个条件。
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int candy(vector &ratings) + { + int len = ratings.size(); + if (len < 2) + return len; + int candy[len + 1]; + candy[0] = 1; + for (int i = 1; i < len; i++) + { + if (ratings[i] > ratings[i - 1]) + candy[i] = candy[i - 1] + 1; + else + candy[i] = 1; + } + int ans = 0; + for (int i = len - 1; i > 0; i--) + { + if (candy[i] >= candy[i - 1] && ratings[i] < ratings[i - 1]) + candy[i - 1] = max(candy[i - 1], candy[i] + 1); + ans += candy[i]; + } + return ans + candy[0]; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/48.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/48.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..b78c7daad661d2c7e0f3f8035a36b31dc342fe75 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/48.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-dc71d0ff18eb49d79792f969fe3e4e12", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/48.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/48.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..1e1246b15c4f88f2dbe026904bf871df311dbc60 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/48.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "104810fc2b7b43be9636eda4d798839b", + "author": "csdn.net", + "keywords": "字典树,记忆化搜索,哈希表,字符串,动态规划,回溯", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/48.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/48.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..05bdff80431fd0056f8725387cc8070d48fa265a --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/48.exercises/solution.md" @@ -0,0 +1,129 @@ +# 单词拆分 II + +

给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,在字符串中增加空格来构建一个句子,使得句子中所有的单词都在词典中。返回所有这些可能的句子。

+ +

说明:

+ +
    +
  • 分隔时可以重复使用字典中的单词。
  • +
  • 你可以假设字典中没有重复的单词。
  • +
+ +

示例 1:

+ +
输入:
+s = "catsanddog"
+wordDict = ["cat", "cats", "and", "sand", "dog"]
+输出:
+[
+  "cats and dog",
+  "cat sand dog"
+]
+
+ +

示例 2:

+ +
输入:
+s = "pineapplepenapple"
+wordDict = ["apple", "pen", "applepen", "pine", "pineapple"]
+输出:
+[
+  "pine apple pen apple",
+  "pineapple pen apple",
+  "pine applepen apple"
+]
+解释: 注意你可以重复使用字典中的单词。
+
+ +

示例 3:

+ +
输入:
+s = "catsandog"
+wordDict = ["cats", "dog", "sand", "and", "cat"]
+输出:
+[]
+
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + vector res; + unordered_set wordset; + unordered_set lenset; + vector wordBreak(string s, vector &wordDict) + { + for (const auto &w : wordDict) + { + wordset.insert(w); + lenset.insert(w.size()); + } + vector dp(s.size() + 1, 0); + dp[0] = 1; + for (int i = 1; i <= s.size(); ++i) + { + for (const auto &j : lenset) + { + if (i >= j && dp[i - j] && wordset.count(s.substr(i - j, j))) + dp[i] = 1; + } + } + + if (dp.back() == 0) + return res; + backtrack(dp, 0, s, ""); + return res; + } + + void backtrack(vector &dp, int idx, string &s, string tmp) + { + if (idx == s.size()) + { + tmp.pop_back(); + res.push_back(tmp); + return; + } + + for (int i = idx + 1; i < dp.size(); ++i) + { + if (dp[i] == 1 && wordset.count(s.substr(idx, i - idx))) + { + backtrack(dp, i, s, tmp + s.substr(idx, i - idx) + " "); + } + } + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/49.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/49.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..76f8c6b975ea3d6ef991f4021021b384b568774d --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/49.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-19c4d2ed874a4229bed1cfffb35fa37c", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/49.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/49.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..e6449a05f288fcad8da01dd6c75f6524fa08991b --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/49.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "3140fe1100a441829c2fa398e3987f00", + "author": "csdn.net", + "keywords": "几何,哈希表,数学", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/49.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/49.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..33c07367782b0e45734dfb1a815158104ed77aca --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/49.exercises/solution.md" @@ -0,0 +1,110 @@ +# 直线上最多的点数 + +

给你一个数组 points ,其中 points[i] = [xi, yi] 表示 X-Y 平面上的一个点。求最多有多少个点在同一条直线上。

+ +

 

+ +

示例 1:

+ +
+输入:points = [[1,1],[2,2],[3,3]]
+输出:3
+
+ +

示例 2:

+ +
+输入:points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]
+输出:4
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= points.length <= 300
  • +
  • points[i].length == 2
  • +
  • -104 <= xi, yi <= 104
  • +
  • points 中的所有点 互不相同
  • +
+ + +## template + +```cpp +#include +using namespace std; + +struct Point +{ + int x; + int y; + Point() : x(0), y(0) {} + Point(int a, int b) : x(a), y(b) {} +}; + +class Solution +{ +public: + int maxPoints(vector &points) + { + int ans = 0; + for (int i = 0; i < points.size(); ++i) + { + map, int> m; + int p = 1; + for (int j = i + 1; j < points.size(); ++j) + { + if (points[i].x == points[j].x && (points[i].y == points[j].y)) + { + ++p; + continue; + } + int dx = points[j].x - points[i].x; + int dy = points[j].y - points[i].y; + int d = gcd(dx, dy); + ++m[{dx / d, dy / d}]; + } + ans = max(ans, p); + for (auto it = m.begin(); it != m.end(); ++it) + { + ans = max(ans, it->second + p); + } + } + return ans; + } + int gcd(int a, int b) + { + return (b == 0) ? a : gcd(b, a % b); + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/50.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/50.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..82c65ebcf5d750832f823970c750ec35e46e0378 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/50.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-16b098a417204953a4caabb304f6db9f", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/50.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/50.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..4a7942fa78c674ded8372c5b8f6131f89968b661 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/50.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "eec0e728b9714adaa9f3b0d1958b3834", + "author": "csdn.net", + "keywords": "数组,二分查找", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/50.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/50.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..21c12edbba038cd87b8dd99155a25ca958a4cb29 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/50.exercises/solution.md" @@ -0,0 +1,103 @@ +# 寻找旋转排序数组中的最小值 II + +已知一个长度为 n 的数组,预先按照升序排列,经由 1n旋转 后,得到输入数组。例如,原数组 nums = [0,1,4,4,5,6,7] 在变化后可能得到: +
    +
  • 若旋转 4 次,则可以得到 [4,5,6,7,0,1,4]
  • +
  • 若旋转 7 次,则可以得到 [0,1,4,4,5,6,7]
  • +
+ +

注意,数组 [a[0], a[1], a[2], ..., a[n-1]] 旋转一次 的结果为数组 [a[n-1], a[0], a[1], a[2], ..., a[n-2]]

+ +

给你一个可能存在 重复 元素值的数组 nums ,它原来是一个升序排列的数组,并按上述情形进行了多次旋转。请你找出并返回数组中的 最小元素

+ +

 

+ +

示例 1:

+ +
+输入:nums = [1,3,5]
+输出:1
+
+ +

示例 2:

+ +
+输入:nums = [2,2,2,0,1]
+输出:0
+
+ +

 

+ +

提示:

+ +
    +
  • n == nums.length
  • +
  • 1 <= n <= 5000
  • +
  • -5000 <= nums[i] <= 5000
  • +
  • nums 原来是一个升序排序的数组,并进行了 1n 次旋转
  • +
+ +

 

+ +

进阶:

+ + + + +## template + +```cpp + +#include +using namespace std; + +class Solution +{ +public: + int findMin(vector &nums) + { + + int left = 0, right = nums.size() - 1; + while (left < right) + { + int mid = left + (right - left) / 2; + if (nums[mid] < nums[right]) + right = mid; + else if (nums[mid] > nums[right]) + left = mid + 1; + else if (nums[mid] == nums[right]) + right--; + } + return nums[right]; + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/51.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/51.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..fded30b1dcb53244de8f749ded648e79c0030cc3 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/51.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-d7a599592aa24aff848013c6ec15cf10", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/51.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/51.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..760164dc5d312b3eb31296b28affc6cc2a529a36 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/51.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "8ae901e74c254416b4765e3f64e86f2c", + "author": "csdn.net", + "keywords": "数组,桶排序,基数排序,排序", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/51.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/51.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..f5ddf1629a9ae743f23e1f7ec0d6aa1ebdeb40df --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/51.exercises/solution.md" @@ -0,0 +1,83 @@ +# 最大间距 + +

给定一个无序的数组,找出数组在排序之后,相邻元素之间最大的差值。

+ +

如果数组元素个数小于 2,则返回 0。

+ +

示例 1:

+ +
输入: [3,6,9,1]
+输出: 3
+解释: 排序后的数组是 [1,3,6,9], 其中相邻元素 (3,6) 和 (6,9) 之间都存在最大差值 3。
+ +

示例 2:

+ +
输入: [10]
+输出: 0
+解释: 数组元素个数小于 2,因此返回 0。
+ +

说明:

+ +
    +
  • 你可以假设数组中所有元素都是非负整数,且数值在 32 位有符号整数范围内。
  • +
  • 请尝试在线性时间复杂度和空间复杂度的条件下解决此问题。
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int maximumGap(vector &nums) + { + set st(nums.begin(), nums.end()); + int res = 0, pre = INT_MIN; + for (auto iter = st.begin(); iter != st.end(); ++iter) + { + if (pre == INT_MIN) + { + pre = *iter; + continue; + } + else + { + res = max(res, *iter - pre); + pre = *iter; + } + } + return res; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/52.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/52.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..ea35684627ec034c6d3a4c201d11aaac9edc9791 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/52.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-296ab2fd88934525b5653ef7114a0358", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/52.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/52.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..d1413c7e036fe6ddc2001940debad0be87e94133 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/52.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "7e1ff136064f405ea80673bf66bfbbfa", + "author": "csdn.net", + "keywords": "数组,动态规划,矩阵", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/52.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/52.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..6bd57595b872430b008b4d5d1251554a30e6c352 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/52.exercises/solution.md" @@ -0,0 +1,122 @@ +# 地下城游戏 + + + +

一些恶魔抓住了公主(P)并将她关在了地下城的右下角。地下城是由 M x N 个房间组成的二维网格。我们英勇的骑士(K)最初被安置在左上角的房间里,他必须穿过地下城并通过对抗恶魔来拯救公主。

+ +

骑士的初始健康点数为一个正整数。如果他的健康点数在某一时刻降至 0 或以下,他会立即死亡。

+ +

有些房间由恶魔守卫,因此骑士在进入这些房间时会失去健康点数(若房间里的值为负整数,则表示骑士将损失健康点数);其他房间要么是空的(房间里的值为 0),要么包含增加骑士健康点数的魔法球(若房间里的值为正整数,则表示骑士将增加健康点数)。

+ +

为了尽快到达公主,骑士决定每次只向右或向下移动一步。

+ +

 

+ +

编写一个函数来计算确保骑士能够拯救到公主所需的最低初始健康点数。

+ +

例如,考虑到如下布局的地下城,如果骑士遵循最佳路径 右 -> 右 -> 下 -> 下,则骑士的初始健康点数至少为 7

+ + + + + + + + + + + + + + + + + +
-2 (K)-33
-5-101
1030-5 (P)
+ + +

 

+ +

说明:

+ +
    +
  • +

    骑士的健康点数没有上限。

    +
  • +
  • 任何房间都可能对骑士的健康点数造成威胁,也可能增加骑士的健康点数,包括骑士进入的左上角房间以及公主被监禁的右下角房间。
  • +
+ +## template + +```cpp + +#include +using namespace std; + +class Solution +{ +public: + int calculateMinimumHP(vector> &dungeon) + { + int row = dungeon.size(); + int col = dungeon[0].size(); + int dp[row][col] = {0}; + dp[row - 1][col - 1] = max(1 - dungeon[row - 1][col - 1], 1); + for (int i = row - 2; i >= 0; i--) + { + dp[i][col - 1] = max(dp[i + 1][col - 1] - dungeon[i][col - 1], 1); + } + for (int i = col - 2; i >= 0; i--) + { + dp[row - 1][i] = max(dp[row - 1][i + 1] - dungeon[row - 1][i], 1); + } + for (int i = row - 2; i >= 0; i--) + { + for (int j = col - 2; j >= 0; j--) + { + dp[i][j] = max(min(dp[i + 1][j], dp[i][j + 1]) - dungeon[i][j], 1); + } + } + + return dp[0][0]; + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/53.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/53.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..cdb36e93c09049c7e77107fad2f0e0f026d51b39 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/53.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-4aeca3661ce143d0bbfd73f6e72f11e9", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/53.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/53.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..30aed40d6167618a80f7ad947fff635b70d5a34a --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/53.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "72ab423ada734563aa9655cef722af73", + "author": "csdn.net", + "keywords": "数组,动态规划", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/53.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/53.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..9fb07084453735012ae91373c98730e9e29a63b7 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/53.exercises/solution.md" @@ -0,0 +1,101 @@ +# 买卖股票的最佳时机 IV + +

给定一个整数数组 prices ,它的第 i 个元素 prices[i] 是一支给定的股票在第 i 天的价格。

+ +

设计一个算法来计算你所能获取的最大利润。你最多可以完成 k 笔交易。

+ +

注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。

+ +

 

+ +

示例 1:

+ +
+输入:k = 2, prices = [2,4,1]
+输出:2
+解释:在第 1 天 (股票价格 = 2) 的时候买入,在第 2 天 (股票价格 = 4) 的时候卖出,这笔交易所能获得利润 = 4-2 = 2 。
+ +

示例 2:

+ +
+输入:k = 2, prices = [3,2,6,5,0,3]
+输出:7
+解释:在第 2 天 (股票价格 = 2) 的时候买入,在第 3 天 (股票价格 = 6) 的时候卖出, 这笔交易所能获得利润 = 6-2 = 4 。
+     随后,在第 5 天 (股票价格 = 0) 的时候买入,在第 6 天 (股票价格 = 3) 的时候卖出, 这笔交易所能获得利润 = 3-0 = 3 。
+ +

 

+ +

提示:

+ +
    +
  • 0 <= k <= 100
  • +
  • 0 <= prices.length <= 1000
  • +
  • 0 <= prices[i] <= 1000
  • +
+ + +## template + +```cpp + +#include +using namespace std; + +class Solution +{ +public: + int maxProfit(int k, vector &prices) + { + const int len = prices.size(); + if (len <= 1 || k == 0) + return 0; + if (k > len / 2) + k = len / 2; + const int count = k; + int buy[count]; + int sell[count]; + for (int i = 0; i < count; ++i) + { + buy[i] = -prices[0]; + sell[i] = 0; + } + for (int i = 1; i < len; ++i) + { + buy[0] = max(buy[0], -prices[i]); + sell[0] = max(sell[0], buy[0] + prices[i]); + for (int j = count - 1; j > 0; --j) + { + buy[j] = max(buy[j], sell[j - 1] - prices[i]); + sell[j] = max(buy[j] + prices[i], sell[j]); + } + } + return sell[count - 1]; + } +}; +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/54.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/54.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..b871df9624cfbde181d67b2aef7355d6d8b576d3 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/54.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-ab7610050b14427bb38fe76c6e8710c5", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/54.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/54.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..7b05d736b8d2e3fc9cfbe53c4c7ff1b1f587cf11 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/54.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "25f9587f51f1491795478d8603b141c9", + "author": "csdn.net", + "keywords": "字典树,数组,字符串,回溯,矩阵", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/54.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/54.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..3b47be88bd12a40f8f38fe890ec1994c4bd74918 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/54.exercises/solution.md" @@ -0,0 +1,159 @@ +# 单词搜索 II + +

给定一个 m x n 二维字符网格 board 和一个单词(字符串)列表 words,找出所有同时在二维网格和字典中出现的单词。

+ +

单词必须按照字母顺序,通过 相邻的单元格 内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一个单元格内的字母在一个单词中不允许被重复使用。

+ +

 

+ +

示例 1:

+ +
+输入:board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]], words = ["oath","pea","eat","rain"]
+输出:["eat","oath"]
+
+ +

示例 2:

+ +
+输入:board = [["a","b"],["c","d"]], words = ["abcb"]
+输出:[]
+
+ +

 

+ +

提示:

+ +
    +
  • m == board.length
  • +
  • n == board[i].length
  • +
  • 1 <= m, n <= 12
  • +
  • board[i][j] 是一个小写英文字母
  • +
  • 1 <= words.length <= 3 * 104
  • +
  • 1 <= words[i].length <= 10
  • +
  • words[i] 由小写英文字母组成
  • +
  • words 中的所有字符串互不相同
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + struct Node + { + bool isflag = false; + Node *next[27] = {}; + }; + set res; + vector ans; + Node *root; + vector dirx{0, 0, 1, -1}; + vector diry{1, -1, 0, 0}; + bool flag; + + void createtree(vector &words) + { + root = new Node(); + + for (auto w : words) + { + Node *p = root; + for (int i = 0; i < w.length(); i++) + { + if (p->next[w[i] - 'a'] == NULL) + { + p->next[w[i] - 'a'] = new Node(); + } + p = p->next[w[i] - 'a']; + } + p->isflag = true; + } + } + void backtrack(vector> &board, vector> visited, int row, int col, Node *roott, string cur) + { + cur += board[row][col]; + roott = roott->next[board[row][col] - 'a']; + if (!roott) + return; + if (roott->isflag == true) + { + + res.insert(cur); + flag = true; + } + visited[row][col] = true; + + for (int i = 0; i < 4; i++) + { + + int nx = row + dirx[i]; + int ny = col + diry[i]; + if (nx < 0 || ny < 0 || nx >= board.size() || ny >= board[0].size()) + continue; + if (visited[nx][ny] == false) + { + backtrack(board, visited, nx, ny, roott, cur); + } + } + } + vector findWords(vector> &board, vector &words) + { + + if (board.size() == 0 || words.size() == 0) + return ans; + createtree(words); + + for (int i = 0; i < board.size(); i++) + { + for (int j = 0; j < board[i].size(); j++) + { + Node *p = root; + flag = false; + if (p->next[board[i][j] - 'a']) + { + vector> visited{board.size(), vector(board[0].size(), false)}; + backtrack(board, visited, i, j, p, ""); + } + } + } + set::iterator it; + for (it = res.begin(); it != res.end(); it++) + ans.push_back(*it); + return ans; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/55.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/55.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..ea49640b1bdc668a89421979f811f2e57e8abe1b --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/55.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-cd6a68f0c68849f2be19d401b84309db", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/55.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/55.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..9c61a0279e4a4f51c04e2b3402fc0087adef8aff --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/55.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "b23f7ff732e7454e84bac4dba3cf95da", + "author": "csdn.net", + "keywords": "字符串,字符串匹配,哈希函数,滚动哈希", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/55.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/55.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..6edbda8461fd2a4615bd8ed30f57f9e0246b8b73 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/55.exercises/solution.md" @@ -0,0 +1,114 @@ +# 最短回文串 + +

给定一个字符串 s,你可以通过在字符串前面添加字符将其转换为回文串。找到并返回可以用这种方式转换的最短回文串。

+ +

 

+ +

示例 1:

+ +
+输入:s = "aacecaaa"
+输出:"aaacecaaa"
+
+ +

示例 2:

+ +
+输入:s = "abcd"
+输出:"dcbabcd"
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= s.length <= 5 * 104
  • +
  • s 仅由小写英文字母组成
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + string shortestPalindrome(string s) + { + + string rev(s); + reverse(rev.begin(), rev.end()); + ; + string combine = s + "#" + rev; + + vector lps(combine.length(), 0); + int remove = getLPS(combine, lps); + + string prepend = rev.substr(0, rev.length() - remove); + return prepend + s; + } + + int getLPS(string s, vector &lps) + { + + int j = 0, i = 1; + + while (i < s.length()) + { + + if (s[i] == s[j]) + { + lps[i] = j + 1; + i++; + j++; + } + else + { + + if (j != 0) + { + j = lps[j - 1]; + } + else + { + lps[i] = 0; + i++; + } + } + } + return lps[lps.size() - 1]; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/56.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/56.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..81e62a52af29a376df11af87acb57358a0689488 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/56.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-572dd30849c445fe93450dec47c48694", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/56.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/56.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..7d9cc280610fe9f6675114c3c6c4b89540a0fe4d --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/56.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "cb4c1989571145b3a29409a0eddf00ad", + "author": "csdn.net", + "keywords": "树状数组,线段树,数组,分治,有序集合,扫描线,堆(优先队列)", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/56.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/56.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..c3286e1ca5ae14e92bfa8df3219921b3b58c6377 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/56.exercises/solution.md" @@ -0,0 +1,111 @@ +# 天际线问题 + +

城市的天际线是从远处观看该城市中所有建筑物形成的轮廓的外部轮廓。给你所有建筑物的位置和高度,请返回由这些建筑物形成的 天际线

+ +

每个建筑物的几何信息由数组 buildings 表示,其中三元组 buildings[i] = [lefti, righti, heighti] 表示:

+ +
    +
  • lefti 是第 i 座建筑物左边缘的 x 坐标。
  • +
  • righti 是第 i 座建筑物右边缘的 x 坐标。
  • +
  • heighti 是第 i 座建筑物的高度。
  • +
+ +

天际线 应该表示为由 “关键点” 组成的列表,格式 [[x1,y1],[x2,y2],...] ,并按 x 坐标 进行 排序关键点是水平线段的左端点。列表中最后一个点是最右侧建筑物的终点,y 坐标始终为 0 ,仅用于标记天际线的终点。此外,任何两个相邻建筑物之间的地面都应被视为天际线轮廓的一部分。

+ +

注意:输出天际线中不得有连续的相同高度的水平线。例如 [...[2 3], [4 5], [7 5], [11 5], [12 7]...] 是不正确的答案;三条高度为 5 的线应该在最终输出中合并为一个:[...[2 3], [4 5], [12 7], ...]

+ +

 

+ +

示例 1:

+ +
+输入:buildings = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]]
+输出:[[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]]
+解释:
+图 A 显示输入的所有建筑物的位置和高度,
+图 B 显示由这些建筑物形成的天际线。图 B 中的红点表示输出列表中的关键点。
+ +

示例 2:

+ +
+输入:buildings = [[0,2,3],[2,5,3]]
+输出:[[0,3],[5,0]]
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= buildings.length <= 104
  • +
  • 0 <= lefti < righti <= 231 - 1
  • +
  • 1 <= heighti <= 231 - 1
  • +
  • buildingslefti 非递减排序
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + vector> getSkyline(vector> &buildings) + { + vector> h, res; + multiset m; + int pre = 0, cur = 0; + for (auto &a : buildings) + { + h.push_back({a[0], -a[2]}); + h.push_back({a[1], a[2]}); + } + sort(h.begin(), h.end()); + m.insert(0); + for (auto &a : h) + { + if (a.second < 0) + m.insert(-a.second); + else + m.erase(m.find(a.second)); + cur = *m.rbegin(); + if (cur != pre) + { + res.push_back({a.first, cur}); + pre = cur; + } + } + return res; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/57.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/57.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..96df3c73bc4d8bc20d97de7939d53b937e7db0c8 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/57.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-88bbdbf9e14241978caed8e0c240060b", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/57.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/57.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..7faf3f7a28e96f1612d550215b86e1ef288dc5f7 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/57.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "baff5b234a504bae989fd669da2cfe46", + "author": "csdn.net", + "keywords": "栈,递归,数学,字符串", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/57.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/57.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..8ffe591ae033b737f6f759580edfa871051c355f --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/57.exercises/solution.md" @@ -0,0 +1,149 @@ +# 基本计算器 + +

给你一个字符串表达式 s ,请你实现一个基本计算器来计算并返回它的值。

+ +

 

+ +

示例 1:

+ +
+输入:s = "1 + 1"
+输出:2
+
+ +

示例 2:

+ +
+输入:s = " 2-1 + 2 "
+输出:3
+
+ +

示例 3:

+ +
+输入:s = "(1+(4+5+2)-3)+(6+8)"
+输出:23
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= s.length <= 3 * 105
  • +
  • s 由数字、'+''-''('')'、和 ' ' 组成
  • +
  • s 表示一个有效的表达式
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int calculate(string s) + { + stack myStack; + stack myOperator; + int i; + for (i = 0; i < s.length(); i++) + { + while (i < s.length() && s[i] == ' ') + i++; + if (i == s.length()) + break; + if (s[i] == '+' || s[i] == '-' || s[i] == '(') + myOperator.push(s[i]); + else if (s[i] == ')') + { + while (myOperator.top() != '(') + { + int element1 = myStack.top(); + myStack.pop(); + int element2 = myStack.top(); + myStack.pop(); + char op = myOperator.top(); + myOperator.pop(); + if (op == '+') + myStack.push(element1 + element2); + else if (op == '-') + myStack.push(element2 - element1); + } + if (!myOperator.empty()) + myOperator.pop(); + while (!myOperator.empty() && (myOperator.top() != '(')) + { + int element1 = myStack.top(); + myStack.pop(); + int element2 = myStack.top(); + myStack.pop(); + char op = myOperator.top(); + myOperator.pop(); + if (op == '+') + myStack.push(element1 + element2); + else if (op == '-') + myStack.push(element2 - element1); + } + } + else + { + + long long int number = 0; + int j = i; + while (j < s.length() && (s[j] - '0' <= 9) && (s[j] - '0' >= 0)) + { + number = number * 10 + (s[j] - '0'); + j++; + } + i = j - 1; + myStack.push(number); + while (!myOperator.empty() && (myOperator.top() != '(')) + { + int element1 = myStack.top(); + myStack.pop(); + int element2 = myStack.top(); + myStack.pop(); + char op = myOperator.top(); + myOperator.pop(); + if (op == '+') + myStack.push(element1 + element2); + else if (op == '-') + myStack.push(element2 - element1); + } + } + } + return myStack.top(); + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/58.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/58.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..c10f06b4c34a99e64e17f716f2369dc7a5466741 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/58.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-61f9fc10dc864281b7a95db6089242dd", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/58.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/58.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..637e23f0c04afbd39fb77620f648f26289fff5d3 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/58.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "b5a670ea8b284444ba5acb0d328c5c97", + "author": "csdn.net", + "keywords": "递归,数学,动态规划", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/58.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/58.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..554a174fb02f8bf6d12685006267e18400506f1c --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/58.exercises/solution.md" @@ -0,0 +1,80 @@ +# 数字 1 的个数 + +

给定一个整数 n,计算所有小于等于 n 的非负整数中数字 1 出现的个数。

+ +

 

+ +

示例 1:

+ +
+输入:n = 13
+输出:6
+
+ +

示例 2:

+ +
+输入:n = 0
+输出:0
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= n <= 109
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int countDigitOne(int n) + { + int cnt = 0; + for (long int i = 1; i <= n; i *= 10) + { + int a = n / i, b = n % i; + cnt += (a + 8) / 10 * i + (a % 10 == 1) * (b + 1); + if (i == 1000000000) + break; + } + return cnt; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/59.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/59.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..6d8ff44b627a2681c23e9ae040f0c795b6b02c62 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/59.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-7a317eb4490c473090a047305ef60283", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/59.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/59.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..684ed8a4f91f029e0e281ef33672d03eefab0872 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/59.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "3b27126a94db47f5ac7e185667a33344", + "author": "csdn.net", + "keywords": "队列,数组,滑动窗口,单调队列,堆(优先队列)", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/59.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/59.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..17c01ca76bfff0c62fe66bf9108557941e059d42 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/59.exercises/solution.md" @@ -0,0 +1,123 @@ +# 滑动窗口最大值 + +

给你一个整数数组 nums,有一个大小为 k 的滑动窗口从数组的最左侧移动到数组的最右侧。你只可以看到在滑动窗口内的 k 个数字。滑动窗口每次只向右移动一位。

+ +

返回滑动窗口中的最大值。

+ +

 

+ +

示例 1:

+ +
+输入:nums = [1,3,-1,-3,5,3,6,7], k = 3
+输出:[3,3,5,5,6,7]
+解释:
+滑动窗口的位置                最大值
+---------------               -----
+[1  3  -1] -3  5  3  6  7       3
+ 1 [3  -1  -3] 5  3  6  7       3
+ 1  3 [-1  -3  5] 3  6  7       5
+ 1  3  -1 [-3  5  3] 6  7       5
+ 1  3  -1  -3 [5  3  6] 7       6
+ 1  3  -1  -3  5 [3  6  7]      7
+
+ +

示例 2:

+ +
+输入:nums = [1], k = 1
+输出:[1]
+
+ +

示例 3:

+ +
+输入:nums = [1,-1], k = 1
+输出:[1,-1]
+
+ +

示例 4:

+ +
+输入:nums = [9,11], k = 2
+输出:[11]
+
+ +

示例 5:

+ +
+输入:nums = [4,-2], k = 2
+输出:[4]
+ +

 

+ +

提示:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • -104 <= nums[i] <= 104
  • +
  • 1 <= k <= nums.length
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + vector maxSlidingWindow(vector &nums, int k) + { + vector ans; + int n = nums.size(); + if (n == 0 || k > n) + return ans; + deque que; + for (int i = 0; i < n; i++) + { + if (!que.empty()) + { + if (i >= que.front() + k) + que.pop_front(); + while (!que.empty() && nums[i] >= nums[que.back()]) + que.pop_back(); + } + que.push_back(i); + if (i + 1 >= k) + ans.push_back(nums[que.front()]); + } + return ans; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/60.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/60.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..1f669946524b08866e07f78e4509f18a88214551 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/60.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-25cba8fca30740af8a49256efbf594cb", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/60.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/60.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..ee63f88cdc067a807749ee9848b4fad5d9f2c1d2 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/60.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "3d2ccc106fcd41818fd74fb68c3e8298", + "author": "csdn.net", + "keywords": "递归,数学,字符串", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/60.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/60.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..3db9507acfec8f01305cf753b3ee150586c1de08 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/60.exercises/solution.md" @@ -0,0 +1,123 @@ +# 整数转换英文表示 + +

将非负整数 num 转换为其对应的英文表示。

+ +

 

+ +

示例 1:

+ +
+输入:num = 123
+输出:"One Hundred Twenty Three"
+
+ +

示例 2:

+ +
+输入:num = 12345
+输出:"Twelve Thousand Three Hundred Forty Five"
+
+ +

示例 3:

+ +
+输入:num = 1234567
+输出:"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"
+
+ +

示例 4:

+ +
+输入:num = 1234567891
+输出:"One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One"
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= num <= 231 - 1
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + const int Mod[3] = {1000000000, 1000000, 1000}; + string H[3] = {"Billion", "Million", "Thousand"}, + M[8] = {"Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"}, + L[20] = {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", + "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"}; + void update(string &ans) + { + ans += ans == "" ? "" : " "; + } + string numberToWords2(int num) + { + if (num < 20) + return L[num]; + string ans; + if (num >= 100) + ans += L[num / 100] + " Hundred", num %= 100; + if (num == 0) + return ans; + else if (num < 20) + update(ans), ans += L[num]; + else + { + update(ans), ans += M[num / 10 - 2], num %= 10; + if (num == 0) + return ans; + else + update(ans), ans += L[num]; + } + return ans; + } + string numberToWords(int num) + { + if (num < 20) + return L[num]; + string ans; + for (int i = 0; i < 3; ++i) + if (num >= Mod[i]) + update(ans), ans += numberToWords2(num / Mod[i]) + " " + H[i], num %= Mod[i]; + if (num) + update(ans), ans += numberToWords2(num); + return ans; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/61.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/61.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..730cc693dcdd31288e1ce1b068265952af80fc47 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/61.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-9148dd1d0d824227a0f66243065d8d5e", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/61.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/61.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..b38f8fdff59a336bf05d0da808618ca8f91355f4 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/61.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "fae69384ffea4b4fb4c8a9c37d8a967e", + "author": "csdn.net", + "keywords": "数学,字符串,回溯", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/61.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/61.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..6dde1b7190ef56c282302f93e7bb3af51aa6f9eb --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/61.exercises/solution.md" @@ -0,0 +1,114 @@ +# 给表达式添加运算符 + +

给定一个仅包含数字 0-9 的字符串 num 和一个目标值整数 target ,在 num 的数字之间添加 二元 运算符(不是一元)+- 或 * ,返回所有能够得到目标值的表达式。

+ +

 

+ +

示例 1:

+ +
+输入: num = "123", target = 6
+输出: ["1+2+3", "1*2*3"] 
+
+ +

示例 2:

+ +
+输入: num = "232", target = 8
+输出: ["2*3+2", "2+3*2"]
+ +

示例 3:

+ +
+输入: num = "105", target = 5
+输出: ["1*0+5","10-5"]
+ +

示例 4:

+ +
+输入: num = "00", target = 0
+输出: ["0+0", "0-0", "0*0"]
+
+ +

示例 5:

+ +
+输入: num = "3456237490", target = 9191
+输出: []
+ +

 

+ +

提示:

+ +
    +
  • 1 <= num.length <= 10
  • +
  • num 仅含数字
  • +
  • -231 <= target <= 231 - 1
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + vector addOperators(string num, int target) + { + vector res; + addOperatorsDFS(num, target, 0, 0, "", res); + return res; + } + + void addOperatorsDFS(string num, int target, long long diff, long long curNum, string out, vector &res) + { + if (num.size() == 0 && curNum == target) + res.push_back(out); + for (int i = 1; i <= num.size(); ++i) + { + string cur = num.substr(0, i); + if (cur.size() > 1 && cur[0] == '0') + return; + string next = num.substr(i); + if (out.size() > 0) + { + addOperatorsDFS(next, target, stoll(cur), curNum + stoll(cur), out + "+" + cur, res); + addOperatorsDFS(next, target, -stoll(cur), curNum - stoll(cur), out + "-" + cur, res); + addOperatorsDFS(next, target, diff * stoll(cur), (curNum - diff) + diff * stoll(cur), out + "*" + cur, res); + } + else + addOperatorsDFS(next, target, stoll(cur), stoll(cur), cur, res); + } + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/62.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/62.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..4bd6167787d23a64b43fb0b8adccda5e42385a59 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/62.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-ed64cc102b034228bec7cdbf38c44a99", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/62.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/62.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..c968b0ec61432468d2cfa82cd2ddfdb121949e18 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/62.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "dcec5a48b80b494c91f58f095646b76f", + "author": "csdn.net", + "keywords": "设计,双指针,数据流,排序,堆(优先队列)", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/62.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/62.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..98f702180ae3b5b72d2afcddd1bf017bc6512335 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/62.exercises/solution.md" @@ -0,0 +1,98 @@ +# 数据流的中位数 + +

中位数是有序列表中间的数。如果列表长度是偶数,中位数则是中间两个数的平均值。

+ +

例如,

+ +

[2,3,4] 的中位数是 3

+ +

[2,3] 的中位数是 (2 + 3) / 2 = 2.5

+ +

设计一个支持以下两种操作的数据结构:

+ +
    +
  • void addNum(int num) - 从数据流中添加一个整数到数据结构中。
  • +
  • double findMedian() - 返回目前所有元素的中位数。
  • +
+ +

示例:

+ +
addNum(1)
+addNum(2)
+findMedian() -> 1.5
+addNum(3) 
+findMedian() -> 2
+ +

进阶:

+ +
    +
  1. 如果数据流中所有整数都在 0 到 100 范围内,你将如何优化你的算法?
  2. +
  3. 如果数据流中 99% 的整数都在 0 到 100 范围内,你将如何优化你的算法?
  4. +
+ + +## template + +```cpp +#include +using namespace std; + +class MedianFinder +{ +public: + /** initialize your data structure here. */ + MedianFinder() + { + } + + void addNum(int num) + { + auto it = upper_bound(nums.begin(), nums.end(), num); + nums.insert(it, num); + } + + double findMedian() + { + int n = nums.size(); + if (n % 2 == 0) + return 1.0 * (nums[n / 2 - 1] + nums[n / 2]) / 2; + else + return nums[n / 2]; + } + vector nums; +}; + +/** + * Your MedianFinder object will be instantiated and called as such: + * MedianFinder obj = new MedianFinder(); + * obj.addNum(num); + * double param_2 = obj.findMedian(); + */ + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/63.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/63.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..95937e8812ee6535918913d2d623be22f9074e17 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/63.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-b8f9e08b8157416f913906073262a9c6", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/63.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/63.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..68c23ad317b905a0e9dbeb91d42814dc2b29bea0 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/63.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "17181b7f3c6849748a23d6d9a1a9df15", + "author": "csdn.net", + "keywords": "树,深度优先搜索,广度优先搜索,设计,字符串,二叉树", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/63.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/63.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..36524d2a938994aa996430b97de2061c60c216ea --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/63.exercises/solution.md" @@ -0,0 +1,123 @@ +# 二叉树的序列化与反序列化 + +

序列化是将一个数据结构或者对象转换为连续的比特位的操作,进而可以将转换后的数据存储在一个文件或者内存中,同时也可以通过网络传输到另一个计算机环境,采取相反方式重构得到原数据。

+ +

请设计一个算法来实现二叉树的序列化与反序列化。这里不限定你的序列 / 反序列化算法执行逻辑,你只需要保证一个二叉树可以被序列化为一个字符串并且将这个字符串反序列化为原始的树结构。

+ +

提示: 输入输出格式与 LeetCode 目前使用的方式一致,详情请参阅 LeetCode 序列化二叉树的格式。你并非必须采取这种方式,你也可以采用其他的方法解决这个问题。

+ +

 

+ +

示例 1:

+ +
+输入:root = [1,2,3,null,null,4,5]
+输出:[1,2,3,null,null,4,5]
+
+ +

示例 2:

+ +
+输入:root = []
+输出:[]
+
+ +

示例 3:

+ +
+输入:root = [1]
+输出:[1]
+
+ +

示例 4:

+ +
+输入:root = [1,2]
+输出:[1,2]
+
+ +

 

+ +

提示:

+ +
    +
  • 树中结点数在范围 [0, 104]
  • +
  • -1000 <= Node.val <= 1000
  • +
+ + +## template + +```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Codec +{ +public: + string serialize(TreeNode *root) + { + if (!root) + return "#_"; + return to_string(root->val) + "_" + serialize(root->left) + serialize(root->right); + } + + TreeNode *deserialize(string data) + { + cout << data << endl; + queue q; + stringstream ss(data); + string s; + while (getline(ss, s, '_')) + q.push(s); + return help(q); + } + + TreeNode *help(queue &q) + { + auto cur = q.front(); + q.pop(); + if (cur == "#") + return NULL; + auto root = new TreeNode(stoi(cur)); + root->left = help(q); + root->right = help(q); + return root; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/64.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/64.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..67aaced35eebd864b906ccf8a7341570027a1129 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/64.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-19e15a33245e42a0b1aa4c31ee5dc348", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/64.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/64.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..d352d4df42dd1015cdf32cba3e2ffddb979d9549 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/64.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "7f6ed006b6be477e8d0ad716b0fdc2ce", + "author": "csdn.net", + "keywords": "广度优先搜索,字符串,回溯", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/64.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/64.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..1b23a82e90c5cc2bf1f2016e14b674cb564c82de --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/64.exercises/solution.md" @@ -0,0 +1,119 @@ +# 删除无效的括号 + +

给你一个由若干括号和字母组成的字符串 s ,删除最小数量的无效括号,使得输入的字符串有效。

+ +

返回所有可能的结果。答案可以按 任意顺序 返回。

+ +

 

+ +

示例 1:

+ +
+输入:s = "()())()"
+输出:["(())()","()()()"]
+
+ +

示例 2:

+ +
+输入:s = "(a)())()"
+输出:["(a())()","(a)()()"]
+
+ +

示例 3:

+ +
+输入:s = ")("
+输出:[""]
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= s.length <= 25
  • +
  • s 由小写英文字母以及括号 '('')' 组成
  • +
  • s 中至多含 20 个括号
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + vector removeInvalidParentheses(string s) + { + vector ans; + rm(move(s), ans, {'(', ')'}, 0, 0); + if (ans.empty()) + return {""}; + return ans; + } + + void rm(string s, vector &ans, vector brackets, int sea_i, int del_i) + { + int sta = 0; + for (int i = sea_i; i < s.size(); i++) + { + if (s[i] == brackets[0]) + sta++; + else if (s[i] == brackets[1]) + { + sta--; + if (sta < 0) + { + for (int j = del_i; j <= i; j++) + { + if (s[j] == brackets[1] && (j == del_i || s[j - 1] != brackets[1])) + { + string new_s = s.substr(0, j) + s.substr(j + 1); + rm(move(new_s), ans, brackets, i, j); + } + } + return; + } + } + } + + reverse(s.begin(), s.end()); + if (brackets[0] == '(') + rm(move(s), ans, {brackets[1], brackets[0]}, 0, 0); + else + ans.push_back(move(s)); + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/65.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/65.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..dfc104fd380267583d3a763bf554dbdfb337cca3 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/65.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-f41308ed84bb4ef8ad09e564348c103f", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/65.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/65.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..5c1f9aa445b2a251487983c81fd763e84f0cb925 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/65.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "8b8699849ba949a28d934e908e7e0fa0", + "author": "csdn.net", + "keywords": "数组,动态规划", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/65.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/65.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..c81be943483f3f20f344a5e92ccb76873a7da02e --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/65.exercises/solution.md" @@ -0,0 +1,94 @@ +# 戳气球 + +

n 个气球,编号为0n - 1,每个气球上都标有一个数字,这些数字存在数组 nums 中。

+ +

现在要求你戳破所有的气球。戳破第 i 个气球,你可以获得 nums[i - 1] * nums[i] * nums[i + 1] 枚硬币。 这里的 i - 1i + 1 代表和 i 相邻的两个气球的序号。如果 i - 1i + 1 超出了数组的边界,那么就当它是一个数字为 1 的气球。

+ +

求所能获得硬币的最大数量。

+ +

 

+示例 1: + +
+输入:nums = [3,1,5,8]
+输出:167
+解释:
+nums = [3,1,5,8] --> [3,5,8] --> [3,8] --> [8] --> []
+coins =  3*1*5    +   3*5*8   +  1*3*8  + 1*8*1 = 167
+ +

示例 2:

+ +
+输入:nums = [1,5]
+输出:10
+
+ +

 

+ +

提示:

+ +
    +
  • n == nums.length
  • +
  • 1 <= n <= 500
  • +
  • 0 <= nums[i] <= 100
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int maxCoins(vector &nums) + { + vector dpnums(nums.size() + 2, 1); + for (int i = 0, j = 1; i < nums.size(); i++, j++) + dpnums[j] = nums[i]; + + vector> coins(dpnums.size(), vector(dpnums.size(), 0)); + for (int i = 2; i < dpnums.size(); i++) + { + for (int j = 0; j + i < dpnums.size(); j++) + { + for (int k = j + 1; k < j + i; k++) + { + coins[j][j + i] = max(coins[j][j + i], coins[j][k] + coins[k][j + i] + + dpnums[j] * dpnums[k] * dpnums[j + i]); + } + } + } + return coins[0][dpnums.size() - 1]; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/66.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/66.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..e01e2c99b1d20c60cef89a0e9d49df7b46cc72ef --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/66.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-d574cf192da6469f948a09a9d97a071a", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/66.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/66.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..d7d1904d88c4da20e5aa65ed7fcc2f0e93212fae --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/66.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "e89ac694c7044313854e7b7bb303b131", + "author": "csdn.net", + "keywords": "树状数组,线段树,数组,二分查找,分治,有序集合,归并排序", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/66.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/66.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..463e1392cd551c1de6bf2c54df08c04ebd7325b1 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/66.exercises/solution.md" @@ -0,0 +1,141 @@ +# 计算右侧小于当前元素的个数 + +

给你`一个整数数组 nums ,按要求返回一个新数组 counts 。数组 counts 有该性质: counts[i] 的值是  nums[i] 右侧小于 nums[i] 的元素的数量。

+ +

 

+ +

示例 1:

+ +
+输入:nums = [5,2,6,1]
+输出:[2,1,1,0] 
+解释:
+5 的右侧有 2 个更小的元素 (2 和 1)
+2 的右侧仅有 1 个更小的元素 (1)
+6 的右侧有 1 个更小的元素 (1)
+1 的右侧有 0 个更小的元素
+
+ +

示例 2:

+ +
+输入:nums = [-1]
+输出:[0]
+
+ +

示例 3:

+ +
+输入:nums = [-1,-1]
+输出:[0,0]
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • -104 <= nums[i] <= 104
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + struct BSTNode + { + int val; + int count; + BSTNode *left; + BSTNode *right; + BSTNode(int x) : val(x), left(NULL), right(NULL), count(0) {} + }; + + void BST_insert(BSTNode *node, BSTNode *insert_node, int &count_small) + { + if (insert_node->val <= node->val) + { + node->count++; + if (node->left) + { + BST_insert(node->left, insert_node, count_small); + } + else + { + node->left = insert_node; + } + } + else + { + count_small += node->count + 1; + if (node->right) + { + BST_insert(node->right, insert_node, count_small); + } + else + { + node->right = insert_node; + } + } + } + + vector countSmaller(vector &nums) + { + vector result; + vector node_vec; + vector count; + for (int i = nums.size() - 1; i >= 0; i--) + { + node_vec.push_back(new BSTNode(nums[i])); + } + count.push_back(0); + for (int i = 1; i < node_vec.size(); i++) + { + int count_small = 0; + BST_insert(node_vec[0], node_vec[i], count_small); + count.push_back(count_small); + } + for (int i = node_vec.size() - 1; i >= 0; i--) + { + delete node_vec[i]; + result.push_back(count[i]); + } + return result; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/67.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/67.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..2a09bee338d622566c40f00b00ff8ac4f72944bf --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/67.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-d2a1b7ad02a34771b7a2f90f7a9ea1ca", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/67.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/67.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..36222566dfce8efec2912f1b89ca1652ff413de5 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/67.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "1ef1ec9da93d458db404ae7309cc1885", + "author": "csdn.net", + "keywords": "栈,贪心,单调栈", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/67.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/67.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..dec6783eda80d5824c412d2284d00284b0f07e8f --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/67.exercises/solution.md" @@ -0,0 +1,125 @@ +# 拼接最大数 + +

给定长度分别为 m 和 n 的两个数组,其元素由 0-9 构成,表示两个自然数各位上的数字。现在从这两个数组中选出 k (k <= m + n) 个数字拼接成一个新的数,要求从同一个数组中取出的数字保持其在原数组中的相对顺序。

+ +

求满足该条件的最大数。结果返回一个表示该最大数的长度为 k 的数组。

+ +

说明: 请尽可能地优化你算法的时间和空间复杂度。

+ +

示例 1:

+ +
输入:
+nums1 = [3, 4, 6, 5]
+nums2 = [9, 1, 2, 5, 8, 3]
+k = 5
+输出:
+[9, 8, 6, 5, 3]
+ +

示例 2:

+ +
输入:
+nums1 = [6, 7]
+nums2 = [6, 0, 4]
+k = 5
+输出:
+[6, 7, 6, 0, 4]
+ +

示例 3:

+ +
输入:
+nums1 = [3, 9]
+nums2 = [8, 9]
+k = 3
+输出:
+[9, 8, 9]
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + vector maxNumber(vector &nums1, vector &nums2, int k) + { + vector ans; + const int n1 = nums1.size(); + const int n2 = nums2.size(); + for (int k1 = 0; k1 <= k; ++k1) + { + const int k2 = k - k1; + if (k1 > n1 || k2 > n2) + { + continue; + } + ans = max(ans, maxNumber(maxNumber(nums1, k1), maxNumber(nums2, k2))); + } + return ans; + } + +private: + vector maxNumber(const vector &nums, const int k) + { + if (k == 0) + { + return {}; + } + vector ans; + int to_pop = nums.size() - k; + for (const int num : nums) + { + while (!ans.empty() && num > ans.back() && to_pop-- > 0) + { + ans.pop_back(); + } + ans.push_back(num); + } + ans.resize(k); + return ans; + } + + vector maxNumber(const vector &nums1, const vector &nums2) + { + vector ans; + auto s1 = nums1.cbegin(); + auto e1 = nums1.cend(); + auto s2 = nums2.cbegin(); + auto e2 = nums2.cend(); + while (s1 != e1 || s2 != e2) + { + ans.push_back(lexicographical_compare(s1, e1, s2, e2) ? *s2++ : *s1++); + } + return ans; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/68.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/68.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..c898aae76433d1fe393e1e51b39ebbd7da1c19f5 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/68.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-e8d6d5215fc946fe8126be057a8f33bf", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/68.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/68.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..01c0f2c340a4d346ad1580264cab24fa1d6d8b3b --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/68.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "49d7e248a7104b43a2bcb42d3d72d75f", + "author": "csdn.net", + "keywords": "树状数组,线段树,数组,二分查找,分治,有序集合,归并排序", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/68.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/68.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..0a0be9a077d63062df9b7c7127babb0bf6aa1aa1 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/68.exercises/solution.md" @@ -0,0 +1,91 @@ +# 区间和的个数 + +

给你一个整数数组 nums 以及两个整数 lowerupper 。求数组中,值位于范围 [lower, upper] (包含 lower 和 upper)之内的 区间和的个数

+ +

区间和 S(i, j) 表示在 nums 中,位置从 i 到 j 的元素之和,包含 i 和 j (ij)。

+ +

 

+示例 1: + +
+输入:nums = [-2,5,-1], lower = -2, upper = 2
+输出:3
+解释:存在三个区间:[0,0]、[2,2] 和 [0,2] ,对应的区间和分别是:-2 、-1 、2 。
+
+ +

示例 2:

+ +
+输入:nums = [0], lower = 0, upper = 0
+输出:1
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= nums.length <= 105
  • +
  • -231 <= nums[i] <= 231 - 1
  • +
  • -105 <= lower <= upper <= 105
  • +
  • 题目数据保证答案是一个 32 位 的整数
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int countRangeSum(vector &nums, int lower, int upper) + { + int n = nums.size(); + long presum = 0; + + multiset S; + S.insert(0); + int ret = 0; + + for (int i = 0; i < n; i++) + { + presum += nums[i]; + + ret += distance(S.lower_bound(presum - upper), S.upper_bound(presum - lower)); + S.insert(presum); + } + return ret; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/69.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/69.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..261df44421f58e65a9c71cdb1107f17805d94368 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/69.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-3f5b93af46c448b8ae7f658f71441265", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/269.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/69.exercises/solution.json" similarity index 55% rename from "data_source/exercises/\345\233\260\351\232\276/cpp/269.exercises/solution.json" rename to "data/3.dailycode\351\253\230\351\230\266/1.cpp/69.exercises/solution.json" index 701112f1fbd66c31f9195533a6d4e0c2548711f6..563e148180a1c400f21903122f666673746eba49 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/269.exercises/solution.json" +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/69.exercises/solution.json" @@ -1,7 +1,8 @@ { "type": "code_options", "source": "solution.md", - "exercise_id": "62801b47b45a4a19bfcc15f52214ba61", + "exercise_id": "5671bc1bbdd14985ab0221672b319317", "author": "csdn.net", - "keywords": "深度优先搜索,广度优先搜索,图,拓扑排序,数组,字符串" + "keywords": "深度优先搜索,广度优先搜索,图,拓扑排序,记忆化搜索,动态规划", + "notebook_enable": true } \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/69.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/69.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..88cb6e09d079e8d14dbd0a5c04dba13686f61ff3 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/69.exercises/solution.md" @@ -0,0 +1,124 @@ +# 矩阵中的最长递增路径 + +

给定一个 m x n 整数矩阵 matrix ,找出其中 最长递增路径 的长度。

+ +

对于每个单元格,你可以往上,下,左,右四个方向移动。 你 不能对角线 方向上移动或移动到 边界外(即不允许环绕)。

+ +

 

+ +

示例 1:

+ +
+输入:matrix = [[9,9,4],[6,6,8],[2,1,1]]
+输出:4 
+解释:最长递增路径为 [1, 2, 6, 9]
+ +

示例 2:

+ +
+输入:matrix = [[3,4,5],[3,2,6],[2,2,1]]
+输出:4 
+解释:最长递增路径是 [3, 4, 5, 6]。注意不允许在对角线方向上移动。
+
+ +

示例 3:

+ +
+输入:matrix = [[1]]
+输出:1
+
+ +

 

+ +

提示:

+ +
    +
  • m == matrix.length
  • +
  • n == matrix[i].length
  • +
  • 1 <= m, n <= 200
  • +
  • 0 <= matrix[i][j] <= 231 - 1
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + static constexpr int dirs[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; + int m, n; + int longestIncreasingPath(vector> &matrix) + { + if (matrix.size() == 0 || matrix[0].size() == 0) + { + return 0; + } + m = matrix.size(); + n = matrix[0].size(); + int res = 0; + auto memo = vector>(m, vector(n, 0)); + for (int i = 0; i < m; ++i) + { + for (int j = 0; j < n; ++j) + { + if (memo[i][j]) + res = max(res, memo[i][j]); + else + res = max(res, dfs(i, j, matrix, memo)); + } + } + return res; + } + + int dfs(int i, int j, vector> &matrix, vector> &memo) + { + int temp = 1; + for (int k = 0; k < 4; ++k) + { + int x = i + dirs[k][0]; + int y = j + dirs[k][1]; + if ((x >= 0) && (x < m) && (y >= 0) && (y < n) && (matrix[i][j] < matrix[x][y])) + { + if (memo[x][y]) + temp = max(temp, memo[x][y] + 1); + else + temp = max(temp, dfs(x, y, matrix, memo) + 1); + } + } + memo[i][j] = temp; + return temp; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/70.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/70.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..a13fe7d3ef92e60ec0b12309bb64a43ef42cb63b --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/70.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-2ccf8bd80a7549a88c59b83b0a4784cc", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/70.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/70.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..eff10dcf3763a7ea35cd370ce5b7fa477b03ce59 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/70.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "a5843164b52e4063aaaf7002f5f24ace", + "author": "csdn.net", + "keywords": "贪心,数组", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/70.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/70.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..f549a29f2ee60b5e9d2e0975fc5d36b1eea9b3bb --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/70.exercises/solution.md" @@ -0,0 +1,89 @@ +# 按要求补齐数组 + +

给定一个已排序的正整数数组 nums,和一个正整数 n 。从 [1, n] 区间内选取任意个数字补充到 nums 中,使得 [1, n] 区间内的任何数字都可以用 nums 中某几个数字的和来表示。请输出满足上述要求的最少需要补充的数字个数。

+ +

示例 1:

+ +
输入: nums = [1,3], n = 6
+输出: 1 
+解释:
+根据 nums 里现有的组合 [1], [3], [1,3],可以得出 1, 3, 4。
+现在如果我们将 2 添加到 nums 中, 组合变为: [1], [2], [3], [1,3], [2,3], [1,2,3]。
+其和可以表示数字 1, 2, 3, 4, 5, 6,能够覆盖 [1, 6] 区间里所有的数。
+所以我们最少需要添加一个数字。
+ +

示例 2:

+ +
输入: nums = [1,5,10], n = 20
+输出: 2
+解释: 我们需要添加 [2, 4]。
+
+ +

示例 3:

+ +
输入: nums = [1,2,2], n = 5
+输出: 0
+
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int minPatches(vector &nums, int n) + { + long max_sum = 0; + int m = nums.size(); + int cnt = 0; + for (long i = 1, pos = 0; i <= n;) + { + + if (pos >= m || i < nums[pos]) + { + cnt++; + max_sum += i; + } + else + { + max_sum += nums[pos]; + pos++; + } + i = max_sum + 1; + } + return cnt; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/71.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/71.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..56b83c86ecdb08cc0e96255dae9fc0a2be09ee36 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/71.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-cbca99701aee469abf36e38ed0f2f36e", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/71.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/71.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..5a33dbfec45e828ad6393a537cc89360fbf3730b --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/71.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "bcb282c1b7944d67a230d8907c37384c", + "author": "csdn.net", + "keywords": "几何,数组,数学", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/71.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/71.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..6d6563304c69ad070882f4cdf2eb613d9b41c96f --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/71.exercises/solution.md" @@ -0,0 +1,101 @@ +# 路径交叉 + +

给你一个整数数组 distance

+ +

X-Y 平面上的点 (0,0) 开始,先向北移动 distance[0] 米,然后向西移动 distance[1] 米,向南移动 distance[2] 米,向东移动 distance[3] 米,持续移动。也就是说,每次移动后你的方位会发生逆时针变化。

+ +

判断你所经过的路径是否相交。如果相交,返回 true ;否则,返回 false

+ +

 

+ +

示例 1:

+ +
+输入:distance = [2,1,1,2]
+输出:true
+
+ +

示例 2:

+ +
+输入:distance = [1,2,3,4]
+输出:false
+
+ +

示例 3:

+ +
+输入:distance = [1,1,1,1]
+输出:true
+ +

 

+ +

提示:

+ +
    +
  • 1 <= distance.length <= 105
  • +
  • 1 <= distance[i] <= 105
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + bool isSelfCrossing(vector &distance) + { + int all_step = distance.size(), current_step = 0; + + if (all_step < 4) + return false; + + current_step = 2; + + while (current_step < all_step && distance[current_step] > distance[current_step - 2]) + current_step++; + if (current_step == all_step) + return false; + + if (distance[current_step] >= distance[current_step - 2] - (current_step > 3 ? distance[current_step - 4] : 0)) + distance[current_step - 1] -= current_step > 2 ? distance[current_step - 3] : 0; + current_step++; + + while (current_step < all_step && distance[current_step] < distance[current_step - 2]) + current_step++; + + return current_step != all_step; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/72.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/72.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..836c465302c242cadbaebb4e734d875c3c7d2ea9 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/72.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-71f21c0d662d4ea3a6d46384c908cce6", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/72.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/72.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..5f03d64f8ca7634a30bc9c28682b1749d318b58b --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/72.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "7c4227d3d4b340a789a82bf09cd8a2e4", + "author": "csdn.net", + "keywords": "字典树,数组,哈希表,字符串", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/72.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/72.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..5918455c4ee4cb704b14dc5dc931e18717d59d7b --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/72.exercises/solution.md" @@ -0,0 +1,121 @@ +# 回文对 + +

给定一组 互不相同 的单词, 找出所有 不同 的索引对 (i, j),使得列表中的两个单词, words[i] + words[j] ,可拼接成回文串。

+ +

 

+ +

示例 1:

+ +
+输入:words = ["abcd","dcba","lls","s","sssll"]
+输出:[[0,1],[1,0],[3,2],[2,4]] 
+解释:可拼接成的回文串为 ["dcbaabcd","abcddcba","slls","llssssll"]
+
+ +

示例 2:

+ +
+输入:words = ["bat","tab","cat"]
+输出:[[0,1],[1,0]] 
+解释:可拼接成的回文串为 ["battab","tabbat"]
+ +

示例 3:

+ +
+输入:words = ["a",""]
+输出:[[0,1],[1,0]]
+
+  + +

提示:

+ +
    +
  • 1 <= words.length <= 5000
  • +
  • 0 <= words[i].length <= 300
  • +
  • words[i] 由小写英文字母组成
  • +
+ + +## template + +```cpp + +#include +using namespace std; + +class Solution +{ +public: + vector> palindromePairs(vector &words) + { + vector> res; + unordered_map m; + set s; + for (int i = 0; i < words.size(); ++i) + { + m[words[i]] = i; + s.insert(words[i].size()); + } + for (int i = 0; i < words.size(); ++i) + { + string t = words[i]; + int len = t.size(); + reverse(t.begin(), t.end()); + if (m.count(t) && m[t] != i) + { + res.push_back({i, m[t]}); + } + auto a = s.find(len); + for (auto it = s.begin(); it != a; ++it) + { + int d = *it; + if (isValid(t, 0, len - d - 1) && m.count(t.substr(len - d))) + { + res.push_back({i, m[t.substr(len - d)]}); + } + if (isValid(t, d, len - 1) && m.count(t.substr(0, d))) + { + res.push_back({m[t.substr(0, d)], i}); + } + } + } + return res; + } + bool isValid(string t, int left, int right) + { + while (left < right) + { + if (t[left++] != t[right--]) + return false; + } + return true; + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/73.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/73.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..6f186b0ce8685a2d10e207208b55a5f38b061a63 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/73.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-fbeb14ccb2ad450f92f803197d8a2898", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/73.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/73.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..77ace747ebfc7dcb733c97630a993ef5b3e92fd6 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/73.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "4d13553202dd4ff3a8b913e7fcbfdebc", + "author": "csdn.net", + "keywords": "设计,二分查找,有序集合", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/73.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/73.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..c821f1a48eed3f4003016c9f4148132f5e7d097b --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/73.exercises/solution.md" @@ -0,0 +1,172 @@ +# 将数据流变为多个不相交区间 + +

 给你一个由非负整数 a1, a2, ..., an 组成的数据流输入,请你将到目前为止看到的数字总结为不相交的区间列表。

+ +

实现 SummaryRanges 类:

+ +
+
+
    +
  • SummaryRanges() 使用一个空数据流初始化对象。
  • +
  • void addNum(int val) 向数据流中加入整数 val
  • +
  • int[][] getIntervals() 以不相交区间 [starti, endi] 的列表形式返回对数据流中整数的总结。
  • +
+ +

 

+ +

示例:

+ +
+输入:
+["SummaryRanges", "addNum", "getIntervals", "addNum", "getIntervals", "addNum", "getIntervals", "addNum", "getIntervals", "addNum", "getIntervals"]
+[[], [1], [], [3], [], [7], [], [2], [], [6], []]
+输出:
+[null, null, [[1, 1]], null, [[1, 1], [3, 3]], null, [[1, 1], [3, 3], [7, 7]], null, [[1, 3], [7, 7]], null, [[1, 3], [6, 7]]]
+
+解释:
+SummaryRanges summaryRanges = new SummaryRanges();
+summaryRanges.addNum(1);      // arr = [1]
+summaryRanges.getIntervals(); // 返回 [[1, 1]]
+summaryRanges.addNum(3);      // arr = [1, 3]
+summaryRanges.getIntervals(); // 返回 [[1, 1], [3, 3]]
+summaryRanges.addNum(7);      // arr = [1, 3, 7]
+summaryRanges.getIntervals(); // 返回 [[1, 1], [3, 3], [7, 7]]
+summaryRanges.addNum(2);      // arr = [1, 2, 3, 7]
+summaryRanges.getIntervals(); // 返回 [[1, 3], [7, 7]]
+summaryRanges.addNum(6);      // arr = [1, 2, 3, 6, 7]
+summaryRanges.getIntervals(); // 返回 [[1, 3], [6, 7]]
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= val <= 104
  • +
  • 最多调用 addNumgetIntervals 方法 3 * 104
  • +
+
+
+ +

 

+ +

进阶:如果存在大量合并,并且与数据流的大小相比,不相交区间的数量很小,该怎么办?

+ + +## template + +```cpp +#include +using namespace std; + +class SummaryRanges +{ +public: + vector> ans; + unordered_map use; + int size; + /** Initialize your data structure here. */ + SummaryRanges() + { + size = 0; + } + + void addNum(int val) + { + if (use.count(val) != 0) + return; + use[val] = 1; + int i; + for (i = 0; i < size; i++) + if (val < ans[i][0]) + break; + if (i == 0) + { + if (size == 0) + { + ans.insert(ans.begin(), {val, val}); + size++; + } + else if (val + 1 == ans[i][0]) + ans[0][0] = val; + else + { + ans.insert(ans.begin(), {val, val}); + size++; + } + } + else if (i == size) + { + if (val - 1 == ans[i - 1][1]) + ans[i - 1][1] = val; + else + { + ans.push_back({val, val}); + size++; + } + } + else + { + if (val + 1 != ans[i][0] && val - 1 != ans[i - 1][1]) + { + ans.insert(ans.begin() + i, {val, val}); + size++; + } + else if (val + 1 == ans[i][0] && val - 1 == ans[i - 1][1]) + { + ans[i - 1][1] = ans[i][1]; + ans.erase(ans.begin() + i); + size--; + } + else if (val + 1 == ans[i][0]) + { + ans[i][0] = val; + } + else + { + ans[i - 1][1] = val; + } + } + } + + vector> getIntervals() + { + return ans; + } +}; + +/** + * Your SummaryRanges object will be instantiated and called as such: + * SummaryRanges* obj = new SummaryRanges(); + * obj->addNum(val); + * vector> param_2 = obj->getIntervals(); + */ + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/74.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/74.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..0bacc38955596606ca702c5d3e6dec204ac89f37 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/74.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-42f27fdeec37424a8f341b005c5817ad", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/74.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/74.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..68ea003837e693267447aaba20fa3c49fe64c42c --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/74.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "87cb6f4e87f44caba4be82fa4c1458aa", + "author": "csdn.net", + "keywords": "数组,二分查找,动态规划,排序", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/74.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/74.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..1118fc0f6952a9d26f18ade2e65caf36592bcfae --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/74.exercises/solution.md" @@ -0,0 +1,110 @@ +# 俄罗斯套娃信封问题 + +

给你一个二维整数数组 envelopes ,其中 envelopes[i] = [wi, hi] ,表示第 i 个信封的宽度和高度。

+ +

当另一个信封的宽度和高度都比这个信封大的时候,这个信封就可以放进另一个信封里,如同俄罗斯套娃一样。

+ +

请计算 最多能有多少个 信封能组成一组“俄罗斯套娃”信封(即可以把一个信封放到另一个信封里面)。

+ +

注意:不允许旋转信封。

+  + +

示例 1:

+ +
+输入:envelopes = [[5,4],[6,4],[6,7],[2,3]]
+输出:3
+解释:最多信封的个数为 3, 组合为: [2,3] => [5,4] => [6,7]。
+ +

示例 2:

+ +
+输入:envelopes = [[1,1],[1,1],[1,1]]
+输出:1
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= envelopes.length <= 5000
  • +
  • envelopes[i].length == 2
  • +
  • 1 <= wi, hi <= 104
  • +
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int maxEnvelopes(vector> &envelopes) + { + sort(envelopes.begin(), envelopes.end(), comp); + + vector dp(envelopes.size(), 1); + + for (int i = 0; i < envelopes.size(); ++i) + { + for (int j = 0; j < i; ++j) + { + if (envelopes[i][1] > envelopes[j][1]) + dp[i] = dp[i] > dp[j] + 1 ? dp[i] : dp[j] + 1; + } + } + + int res = 0; + for (int i = 0; i < dp.size(); ++i) + res = res > dp[i] ? res : dp[i]; + + return res; + } + + static bool comp(const vector &a, const vector &b) + { + if (a[0] < b[0]) + return true; + else if (a[0] > b[0]) + return false; + else + { + if (a[1] > b[1]) + return true; + else + return false; + } + } +}; + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/75.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/75.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..9287b07debb77ef47ea35aacefc26af72717e182 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/75.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-aef821a970104bb790aa7151f2738112", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/75.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/75.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..0f549776fe33a029ca80edfe16374348688294b5 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/75.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "a4236763673c4399aa681854f79513e3", + "author": "csdn.net", + "keywords": "数组,二分查找,动态规划,矩阵,有序集合", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/75.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/75.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..2de116311a9855a873a2b53179f997ce3ab2cd3b --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/75.exercises/solution.md" @@ -0,0 +1,112 @@ +# 矩形区域不超过 K 的最大数值和 + +

给你一个 m x n 的矩阵 matrix 和一个整数 k ,找出并返回矩阵内部矩形区域的不超过 k 的最大数值和。

+ +

题目数据保证总会存在一个数值和不超过 k 的矩形区域。

+ +

 

+ +

示例 1:

+ +
+输入:matrix = [[1,0,1],[0,-2,3]], k = 2
+输出:2
+解释:蓝色边框圈出来的矩形区域 [[0, 1], [-2, 3]] 的数值和是 2,且 2 是不超过 k 的最大数字(k = 2)。
+
+ +

示例 2:

+ +
+输入:matrix = [[2,2,-1]], k = 3
+输出:3
+
+ +

 

+ +

提示:

+ +
    +
  • m == matrix.length
  • +
  • n == matrix[i].length
  • +
  • 1 <= m, n <= 100
  • +
  • -100 <= matrix[i][j] <= 100
  • +
  • -105 <= k <= 105
  • +
+ +

 

+ +

进阶:如果行数远大于列数,该如何设计解决方案?

+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + int maxSumSubmatrix(vector> &mat, int k) + { + int m = mat.size(), n = mat[0].size(); + vector> sum(m + 1, vector(n + 1, 0)); + for (int i = 1; i <= m; i++) + { + for (int j = 1; j <= n; j++) + { + sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + mat[i - 1][j - 1]; + } + } + int ans = INT_MIN; + for (int top = 1; top <= m; top++) + { + for (int bot = top; bot <= m; bot++) + { + set st; + st.insert(0); + for (int r = 1; r <= n; r++) + { + int right = sum[bot][r] - sum[top - 1][r]; + auto left = st.lower_bound(right - k); + if (left != st.end()) + { + int cur = right - *left; + ans = max(ans, cur); + } + st.insert(right); + } + } + } + return ans; + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/76.exercises/config.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/76.exercises/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..393bf3144203dbb4e54cdd5c42b468d685ce505e --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/76.exercises/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "dailycode-a90c9ada239046bca1194d2abb4df6c4", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/76.exercises/solution.json" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/76.exercises/solution.json" new file mode 100644 index 0000000000000000000000000000000000000000..a1d5ecb6780638bbe950a7ad860dcc9401143da5 --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/76.exercises/solution.json" @@ -0,0 +1,8 @@ +{ + "type": "code_options", + "source": "solution.md", + "exercise_id": "cc8a49e3be2d49f49effc7e672eed57a", + "author": "csdn.net", + "keywords": "数组,扫描线", + "notebook_enable": true +} \ No newline at end of file diff --git "a/data/3.dailycode\351\253\230\351\230\266/1.cpp/76.exercises/solution.md" "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/76.exercises/solution.md" new file mode 100644 index 0000000000000000000000000000000000000000..da0da4b58a1fb37762b8bae99e5fe64a372e707b --- /dev/null +++ "b/data/3.dailycode\351\253\230\351\230\266/1.cpp/76.exercises/solution.md" @@ -0,0 +1,146 @@ +# 完美矩形 + +

我们有 N 个与坐标轴对齐的矩形, 其中 N > 0, 判断它们是否能精确地覆盖一个矩形区域。

+ +

每个矩形用左下角的点和右上角的点的坐标来表示。例如, 一个单位正方形可以表示为 [1,1,2,2]。 ( 左下角的点的坐标为 (1, 1) 以及右上角的点的坐标为 (2, 2) )。

+ +

+ +

示例 1:

+ +
rectangles = [
+  [1,1,3,3],
+  [3,1,4,2],
+  [3,2,4,4],
+  [1,3,2,4],
+  [2,3,3,4]
+]
+
+返回 true。5个矩形一起可以精确地覆盖一个矩形区域。
+
+ +

 

+ +

+ +

示例 2:

+ +
rectangles = [
+  [1,1,2,3],
+  [1,3,2,4],
+  [3,1,4,2],
+  [3,2,4,4]
+]
+
+返回 false。两个矩形之间有间隔,无法覆盖成一个矩形。
+
+ +

 

+ +

+ +

示例 3:

+ +
rectangles = [
+  [1,1,3,3],
+  [3,1,4,2],
+  [1,3,2,4],
+  [3,2,4,4]
+]
+
+返回 false。图形顶端留有间隔,无法覆盖成一个矩形。
+
+ +

 

+ +

+ +

示例 4:

+ +
rectangles = [
+  [1,1,3,3],
+  [3,1,4,2],
+  [1,3,2,4],
+  [2,2,4,4]
+]
+
+返回 false。因为中间有相交区域,虽然形成了矩形,但不是精确覆盖。
+
+ + +## template + +```cpp +#include +using namespace std; + +class Solution +{ +public: + bool isRectangleCover(vector> &ret) + { + set> s; + int x1 = INT_MAX, y1 = INT_MAX, x2 = INT_MIN, y2 = INT_MIN, area = 0; + for (int i = 0; i < ret.size(); ++i) + { + x1 = min(ret[i][0], x1); + x2 = max(ret[i][2], x2); + y1 = min(ret[i][1], y1); + y2 = max(ret[i][3], y2); + area += (ret[i][2] - ret[i][0]) * (ret[i][3] - ret[i][1]); + + if (s.find({ret[i][0], ret[i][1]}) == s.end()) + s.insert({ret[i][0], ret[i][1]}); + else + s.erase({ret[i][0], ret[i][1]}); + + if (s.find({ret[i][2], ret[i][3]}) == s.end()) + s.insert({ret[i][2], ret[i][3]}); + else + s.erase({ret[i][2], ret[i][3]}); + + if (s.find({ret[i][0], ret[i][3]}) == s.end()) + s.insert({ret[i][0], ret[i][3]}); + else + s.erase({ret[i][0], ret[i][3]}); + + if (s.find({ret[i][2], ret[i][1]}) == s.end()) + s.insert({ret[i][2], ret[i][1]}); + else + s.erase({ret[i][2], ret[i][1]}); + } + + if (s.size() != 4 || !s.count({x1, y1}) || !s.count({x1, y2}) || !s.count({x2, y1}) || !s.count({x2, y2})) + return false; + return area == (x2 - x1) * (y2 - y1); + } +}; + + +``` + +## 答案 + +```cpp + +``` + +## 选项 + +### A + +```cpp + +``` + +### B + +```cpp + +``` + +### C + +```cpp + +``` \ No newline at end of file diff --git a/data/tree.json b/data/tree.json index ee6f414dc55f57ce36f3b3699d60ce8f60ea1d72..6eed6bcd8126f8caad4b02f067ec99c1d759e2ef 100644 --- a/data/tree.json +++ b/data/tree.json @@ -885,20 +885,10 @@ "keywords_must": [], "keywords_forbid": [] } - } - ], - "keywords_must": [], - "keywords_forbid": [] - } - }, - { - "java": { - "node_id": "dailycode-aa973b9977cb4929a22ec6c657d84644", - "keywords": [], - "children": [ + }, { "exercises": { - "node_id": "dailycode-6800f6713d5a4e85aa6db48e6c5a8d97", + "node_id": "dailycode-b1b34d10555f424f9012194aff09f895", "keywords": [], "children": [], "keywords_must": [], @@ -907,7 +897,7 @@ }, { "exercises": { - "node_id": "dailycode-a56e385c4b5c46aca7f4e809ca7d9c2f", + "node_id": "dailycode-b34e8ed950f64727b2b4653b8433dc22", "keywords": [], "children": [], "keywords_must": [], @@ -916,7 +906,7 @@ }, { "exercises": { - "node_id": "dailycode-3d37655535b94c67973752f1082916b1", + "node_id": "dailycode-d335de511b684c29bfea723f6d33a0e4", "keywords": [], "children": [], "keywords_must": [], @@ -925,7 +915,7 @@ }, { "exercises": { - "node_id": "dailycode-1ca616758e884630bac67b234def92c8", + "node_id": "dailycode-a83634532b824c769445b10d596917f6", "keywords": [], "children": [], "keywords_must": [], @@ -934,7 +924,7 @@ }, { "exercises": { - "node_id": "dailycode-76e2da179b144ee88079177af1baae8c", + "node_id": "dailycode-c8023cfe856c4678aa96956db32b5470", "keywords": [], "children": [], "keywords_must": [], @@ -943,7 +933,7 @@ }, { "exercises": { - "node_id": "dailycode-f0884125382f41c592c2346b73f34e30", + "node_id": "dailycode-fb518fd9317c4e229cee01ac248ce804", "keywords": [], "children": [], "keywords_must": [], @@ -952,7 +942,7 @@ }, { "exercises": { - "node_id": "dailycode-642fd7e4d1d94f50b103667b52e349de", + "node_id": "dailycode-14e9caac11dc4882b6acbc4e7a4ff49d", "keywords": [], "children": [], "keywords_must": [], @@ -961,7 +951,7 @@ }, { "exercises": { - "node_id": "dailycode-a97f6434fd15477d982f9ef33297caff", + "node_id": "dailycode-163199273b89450f9621cbdf0da4f01b", "keywords": [], "children": [], "keywords_must": [], @@ -970,7 +960,7 @@ }, { "exercises": { - "node_id": "dailycode-4599bbc177164a5fbac3c9116aee0c05", + "node_id": "dailycode-26c2393a211f4f74aae41a5c5b6f1194", "keywords": [], "children": [], "keywords_must": [], @@ -979,7 +969,7 @@ }, { "exercises": { - "node_id": "dailycode-b1d024a612ef4995986230770db68e62", + "node_id": "dailycode-0a92b1231f904f52a9bc75a9e427173d", "keywords": [], "children": [], "keywords_must": [], @@ -988,7 +978,7 @@ }, { "exercises": { - "node_id": "dailycode-bfa08919a0914b6092a54578c976c2db", + "node_id": "dailycode-e74a8997c29746c4800782a33e2c7640", "keywords": [], "children": [], "keywords_must": [], @@ -997,7 +987,7 @@ }, { "exercises": { - "node_id": "dailycode-0eb0d6cdc41643e89bb5683c139216bb", + "node_id": "dailycode-219df52f601244238513e7de7e2003ed", "keywords": [], "children": [], "keywords_must": [], @@ -1006,7 +996,7 @@ }, { "exercises": { - "node_id": "dailycode-0cf6927a16a24e268a24657d6960a95a", + "node_id": "dailycode-55f3974a87a84f75bb2893cb290fde96", "keywords": [], "children": [], "keywords_must": [], @@ -1015,7 +1005,7 @@ }, { "exercises": { - "node_id": "dailycode-f212de10cac247a4bab00cb73e61b645", + "node_id": "dailycode-1651f0143f344641870e403e0fecd732", "keywords": [], "children": [], "keywords_must": [], @@ -1024,7 +1014,7 @@ }, { "exercises": { - "node_id": "dailycode-4373e77e72654321846d4cb7d92b7935", + "node_id": "dailycode-2d3f0bbed569420195f24c6ab63fd904", "keywords": [], "children": [], "keywords_must": [], @@ -1033,7 +1023,7 @@ }, { "exercises": { - "node_id": "dailycode-91a33b05aa5342848cafc5816a49e0d4", + "node_id": "dailycode-709d66df256d4328a79b6e8cb3c2d392", "keywords": [], "children": [], "keywords_must": [], @@ -1042,7 +1032,7 @@ }, { "exercises": { - "node_id": "dailycode-a9a7e4b9222e4162853a11cfdf80ee99", + "node_id": "dailycode-2bc75d75d57b4807a2edf0eb18eb5c8c", "keywords": [], "children": [], "keywords_must": [], @@ -1051,7 +1041,7 @@ }, { "exercises": { - "node_id": "dailycode-60a6ce1c2d794a2bbe410465d3a02887", + "node_id": "dailycode-68803d4d5df0420eabfef657c0df9560", "keywords": [], "children": [], "keywords_must": [], @@ -1060,7 +1050,7 @@ }, { "exercises": { - "node_id": "dailycode-1cd0efc5eab8483ca912341f4320382f", + "node_id": "dailycode-8337bc578dd54305bcbcf6445d06af30", "keywords": [], "children": [], "keywords_must": [], @@ -1069,7 +1059,7 @@ }, { "exercises": { - "node_id": "dailycode-8c4886e800094c849c6eec647e0c04b7", + "node_id": "dailycode-962b9124033e41d49aa3481c7dfab494", "keywords": [], "children": [], "keywords_must": [], @@ -1078,7 +1068,7 @@ }, { "exercises": { - "node_id": "dailycode-9f809286599941568b67aa96b36c603d", + "node_id": "dailycode-bc50522c68bf48fd97e6f613722f66fa", "keywords": [], "children": [], "keywords_must": [], @@ -1087,7 +1077,7 @@ }, { "exercises": { - "node_id": "dailycode-f0382b88c43f411fbf4bf8273bec3247", + "node_id": "dailycode-345aecfe47a24f5aa0a5a616aa82d801", "keywords": [], "children": [], "keywords_must": [], @@ -1096,7 +1086,7 @@ }, { "exercises": { - "node_id": "dailycode-996228f46e754a58b78d9567bb808499", + "node_id": "dailycode-524ced2fd5dd476bbfa3314db321e961", "keywords": [], "children": [], "keywords_must": [], @@ -1105,7 +1095,7 @@ }, { "exercises": { - "node_id": "dailycode-9c270d6326d3421c974562ddce0e3a56", + "node_id": "dailycode-e7e53eb27fac437d9d1a3dbdc258d5bf", "keywords": [], "children": [], "keywords_must": [], @@ -1114,7 +1104,7 @@ }, { "exercises": { - "node_id": "dailycode-4756dcc742414555aafd768d88b1b5a0", + "node_id": "dailycode-15f39c759f9b4aa99bb75b00bcf0580c", "keywords": [], "children": [], "keywords_must": [], @@ -1123,7 +1113,7 @@ }, { "exercises": { - "node_id": "dailycode-d3e5bdffa99e4c26a254dac53bab6424", + "node_id": "dailycode-ae3f500a3fd948b59a5433ed9e3abee5", "keywords": [], "children": [], "keywords_must": [], @@ -1132,7 +1122,7 @@ }, { "exercises": { - "node_id": "dailycode-2bd314f30cd143a5acaf9847ce64e8d1", + "node_id": "dailycode-7259fff1111e46ffa29f196ba542ba00", "keywords": [], "children": [], "keywords_must": [], @@ -1141,7 +1131,7 @@ }, { "exercises": { - "node_id": "dailycode-199440179d394fafb06dc367103b6359", + "node_id": "dailycode-0e10486e4e8640adae0e951917a26845", "keywords": [], "children": [], "keywords_must": [], @@ -1150,7 +1140,7 @@ }, { "exercises": { - "node_id": "dailycode-e7a3cf5d0ffe48a6ae751e69c884fe5f", + "node_id": "dailycode-88db4509fe484d61a6dcf07943003cb1", "keywords": [], "children": [], "keywords_must": [], @@ -1159,7 +1149,7 @@ }, { "exercises": { - "node_id": "dailycode-d733ec126a274808bc4085078f5f93df", + "node_id": "dailycode-510c86fa67d842068f7c3f018e8f89d9", "keywords": [], "children": [], "keywords_must": [], @@ -1168,7 +1158,7 @@ }, { "exercises": { - "node_id": "dailycode-2adfe208aeec4d2fa3eb42cb8361e417", + "node_id": "dailycode-6326da4a969f49dc810d995343223f5e", "keywords": [], "children": [], "keywords_must": [], @@ -1177,7 +1167,7 @@ }, { "exercises": { - "node_id": "dailycode-1aec7acacc4e431e9761929aa7a04af3", + "node_id": "dailycode-50e1cb8edc1d4dc19b4d95ab248cbe36", "keywords": [], "children": [], "keywords_must": [], @@ -1186,7 +1176,7 @@ }, { "exercises": { - "node_id": "dailycode-5fc81f3203724e6bbc28969923a64495", + "node_id": "dailycode-e1a1c4598bdb483a8b73a902222956df", "keywords": [], "children": [], "keywords_must": [], @@ -1195,7 +1185,7 @@ }, { "exercises": { - "node_id": "dailycode-b99fbefc0fd34ea9b5a17db12f45f1c5", + "node_id": "dailycode-3ee24b6deba740379e077abdc180342f", "keywords": [], "children": [], "keywords_must": [], @@ -1204,7 +1194,7 @@ }, { "exercises": { - "node_id": "dailycode-31d9a5c7f596454a800d98f4ffec6e67", + "node_id": "dailycode-73795c2480d4451cbba108521a80078c", "keywords": [], "children": [], "keywords_must": [], @@ -1213,7 +1203,7 @@ }, { "exercises": { - "node_id": "dailycode-8fcebe8098d040f7a3dbbb9a40d79501", + "node_id": "dailycode-541c93e32cbc42deb82573d4759671e5", "keywords": [], "children": [], "keywords_must": [], @@ -1222,7 +1212,7 @@ }, { "exercises": { - "node_id": "dailycode-4b8e2ba0678440539ca1fc73c8852103", + "node_id": "dailycode-9416ddb972a34cf1aa8a10edf76ce65f", "keywords": [], "children": [], "keywords_must": [], @@ -1231,16 +1221,26 @@ }, { "exercises": { - "node_id": "dailycode-69d51623b58146baa7164733d16a104a", + "node_id": "dailycode-27db96ec9b784632b5e93fa1cec6df61", "keywords": [], "children": [], "keywords_must": [], "keywords_forbid": [] } - }, + } + ], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "java": { + "node_id": "dailycode-aa973b9977cb4929a22ec6c657d84644", + "keywords": [], + "children": [ { "exercises": { - "node_id": "dailycode-f82947171c0b4413b5364fc8d0a9abc2", + "node_id": "dailycode-6800f6713d5a4e85aa6db48e6c5a8d97", "keywords": [], "children": [], "keywords_must": [], @@ -1249,7 +1249,7 @@ }, { "exercises": { - "node_id": "dailycode-4a30eebe19474c4fb0a387ab45a684de", + "node_id": "dailycode-a56e385c4b5c46aca7f4e809ca7d9c2f", "keywords": [], "children": [], "keywords_must": [], @@ -1258,7 +1258,7 @@ }, { "exercises": { - "node_id": "dailycode-2ab0d6770e5f46889d71ba2f4b2e1fb1", + "node_id": "dailycode-3d37655535b94c67973752f1082916b1", "keywords": [], "children": [], "keywords_must": [], @@ -1267,7 +1267,7 @@ }, { "exercises": { - "node_id": "dailycode-df2108c0132f4f87a1db8b491de4dc79", + "node_id": "dailycode-1ca616758e884630bac67b234def92c8", "keywords": [], "children": [], "keywords_must": [], @@ -1276,7 +1276,7 @@ }, { "exercises": { - "node_id": "dailycode-3cd29560f5674e679333d243e81115c0", + "node_id": "dailycode-76e2da179b144ee88079177af1baae8c", "keywords": [], "children": [], "keywords_must": [], @@ -1285,7 +1285,7 @@ }, { "exercises": { - "node_id": "dailycode-cd10c107bc354eef83e1b81a46b78db5", + "node_id": "dailycode-f0884125382f41c592c2346b73f34e30", "keywords": [], "children": [], "keywords_must": [], @@ -1294,7 +1294,7 @@ }, { "exercises": { - "node_id": "dailycode-77f941ad05c44053af905fd80f942bd5", + "node_id": "dailycode-642fd7e4d1d94f50b103667b52e349de", "keywords": [], "children": [], "keywords_must": [], @@ -1303,7 +1303,7 @@ }, { "exercises": { - "node_id": "dailycode-00a267eca7a84efdac846774beeb5766", + "node_id": "dailycode-a97f6434fd15477d982f9ef33297caff", "keywords": [], "children": [], "keywords_must": [], @@ -1312,7 +1312,7 @@ }, { "exercises": { - "node_id": "dailycode-a0ba50f39b734de284a9d868affd00a5", + "node_id": "dailycode-4599bbc177164a5fbac3c9116aee0c05", "keywords": [], "children": [], "keywords_must": [], @@ -1321,26 +1321,16 @@ }, { "exercises": { - "node_id": "dailycode-d1b9ca19b0a24258833ae33eac8f8ee6", + "node_id": "dailycode-b1d024a612ef4995986230770db68e62", "keywords": [], "children": [], "keywords_must": [], "keywords_forbid": [] } - } - ], - "keywords_must": [], - "keywords_forbid": [] - } - }, - { - "python": { - "node_id": "dailycode-5219545f25234c5cad33fc2f95fd7880", - "keywords": [], - "children": [ + }, { "exercises": { - "node_id": "dailycode-2eebebfff6fa4188a9711c043407e25f", + "node_id": "dailycode-bfa08919a0914b6092a54578c976c2db", "keywords": [], "children": [], "keywords_must": [], @@ -1349,7 +1339,7 @@ }, { "exercises": { - "node_id": "dailycode-d23a2d27d45a49b197d1cd6eea72f56a", + "node_id": "dailycode-0eb0d6cdc41643e89bb5683c139216bb", "keywords": [], "children": [], "keywords_must": [], @@ -1358,7 +1348,7 @@ }, { "exercises": { - "node_id": "dailycode-6d903ddd2bbf4473b7d0e9d6c0b0c2c8", + "node_id": "dailycode-0cf6927a16a24e268a24657d6960a95a", "keywords": [], "children": [], "keywords_must": [], @@ -1367,7 +1357,7 @@ }, { "exercises": { - "node_id": "dailycode-32ce873ede9141efaa8c63975adf1561", + "node_id": "dailycode-f212de10cac247a4bab00cb73e61b645", "keywords": [], "children": [], "keywords_must": [], @@ -1376,7 +1366,7 @@ }, { "exercises": { - "node_id": "dailycode-94df85e9dbd04a8cb60cec11aa9b170a", + "node_id": "dailycode-4373e77e72654321846d4cb7d92b7935", "keywords": [], "children": [], "keywords_must": [], @@ -1385,7 +1375,7 @@ }, { "exercises": { - "node_id": "dailycode-2e6302bf718d46598da5024957c605a0", + "node_id": "dailycode-91a33b05aa5342848cafc5816a49e0d4", "keywords": [], "children": [], "keywords_must": [], @@ -1394,7 +1384,7 @@ }, { "exercises": { - "node_id": "dailycode-37725ca16b9f48d7a618ebe5d654955d", + "node_id": "dailycode-a9a7e4b9222e4162853a11cfdf80ee99", "keywords": [], "children": [], "keywords_must": [], @@ -1403,7 +1393,7 @@ }, { "exercises": { - "node_id": "dailycode-eb8c1b6d542e4aa6aa9b722336978115", + "node_id": "dailycode-60a6ce1c2d794a2bbe410465d3a02887", "keywords": [], "children": [], "keywords_must": [], @@ -1412,7 +1402,7 @@ }, { "exercises": { - "node_id": "dailycode-0e465e8d70a1454a8aac9dd2da5f9325", + "node_id": "dailycode-1cd0efc5eab8483ca912341f4320382f", "keywords": [], "children": [], "keywords_must": [], @@ -1421,7 +1411,7 @@ }, { "exercises": { - "node_id": "dailycode-95f5fc9c54d0497ab2c97dd8c49b8629", + "node_id": "dailycode-8c4886e800094c849c6eec647e0c04b7", "keywords": [], "children": [], "keywords_must": [], @@ -1430,7 +1420,7 @@ }, { "exercises": { - "node_id": "dailycode-4e18b0172b18463dadaf46362740d7d0", + "node_id": "dailycode-9f809286599941568b67aa96b36c603d", "keywords": [], "children": [], "keywords_must": [], @@ -1439,7 +1429,7 @@ }, { "exercises": { - "node_id": "dailycode-2bef970158ef4ce2bc686d63ee943610", + "node_id": "dailycode-f0382b88c43f411fbf4bf8273bec3247", "keywords": [], "children": [], "keywords_must": [], @@ -1448,7 +1438,7 @@ }, { "exercises": { - "node_id": "dailycode-d722f2ee79964c4ba0ff10be006ed793", + "node_id": "dailycode-996228f46e754a58b78d9567bb808499", "keywords": [], "children": [], "keywords_must": [], @@ -1457,7 +1447,7 @@ }, { "exercises": { - "node_id": "dailycode-5e0a54189fd843a8954fa9ae5aac50a0", + "node_id": "dailycode-9c270d6326d3421c974562ddce0e3a56", "keywords": [], "children": [], "keywords_must": [], @@ -1466,7 +1456,7 @@ }, { "exercises": { - "node_id": "dailycode-a9142d5aeaa848daac6817cae5a08bb1", + "node_id": "dailycode-4756dcc742414555aafd768d88b1b5a0", "keywords": [], "children": [], "keywords_must": [], @@ -1475,7 +1465,7 @@ }, { "exercises": { - "node_id": "dailycode-b3bc51803cda4223ad95594ff9597d61", + "node_id": "dailycode-d3e5bdffa99e4c26a254dac53bab6424", "keywords": [], "children": [], "keywords_must": [], @@ -1484,7 +1474,7 @@ }, { "exercises": { - "node_id": "dailycode-be86731880ca4fb99657c3f64cd64235", + "node_id": "dailycode-2bd314f30cd143a5acaf9847ce64e8d1", "keywords": [], "children": [], "keywords_must": [], @@ -1493,7 +1483,7 @@ }, { "exercises": { - "node_id": "dailycode-a348977e517f4b358abaf20c42988cbf", + "node_id": "dailycode-199440179d394fafb06dc367103b6359", "keywords": [], "children": [], "keywords_must": [], @@ -1502,7 +1492,7 @@ }, { "exercises": { - "node_id": "dailycode-495106c5ee4543a98d00295b797e3982", + "node_id": "dailycode-e7a3cf5d0ffe48a6ae751e69c884fe5f", "keywords": [], "children": [], "keywords_must": [], @@ -1511,7 +1501,7 @@ }, { "exercises": { - "node_id": "dailycode-654c59b4c5de4a82af30051c65b06181", + "node_id": "dailycode-d733ec126a274808bc4085078f5f93df", "keywords": [], "children": [], "keywords_must": [], @@ -1520,7 +1510,7 @@ }, { "exercises": { - "node_id": "dailycode-1dc9532947e14e2aaa9274f1ba3e093e", + "node_id": "dailycode-2adfe208aeec4d2fa3eb42cb8361e417", "keywords": [], "children": [], "keywords_must": [], @@ -1529,7 +1519,7 @@ }, { "exercises": { - "node_id": "dailycode-bb13d528854f425581da02db1f7f053b", + "node_id": "dailycode-1aec7acacc4e431e9761929aa7a04af3", "keywords": [], "children": [], "keywords_must": [], @@ -1538,7 +1528,7 @@ }, { "exercises": { - "node_id": "dailycode-45221df1b0024a78bfef72b49e99492c", + "node_id": "dailycode-5fc81f3203724e6bbc28969923a64495", "keywords": [], "children": [], "keywords_must": [], @@ -1547,7 +1537,7 @@ }, { "exercises": { - "node_id": "dailycode-6a1541c03bbf441a9f896331a5d4cba1", + "node_id": "dailycode-b99fbefc0fd34ea9b5a17db12f45f1c5", "keywords": [], "children": [], "keywords_must": [], @@ -1556,7 +1546,7 @@ }, { "exercises": { - "node_id": "dailycode-5d456f7d55404cf799b24bcc882a1553", + "node_id": "dailycode-31d9a5c7f596454a800d98f4ffec6e67", "keywords": [], "children": [], "keywords_must": [], @@ -1565,7 +1555,7 @@ }, { "exercises": { - "node_id": "dailycode-309fe024bfc848f0b91a68fe6b953057", + "node_id": "dailycode-8fcebe8098d040f7a3dbbb9a40d79501", "keywords": [], "children": [], "keywords_must": [], @@ -1574,7 +1564,7 @@ }, { "exercises": { - "node_id": "dailycode-286abc7bb8fd4a43bba78b881258b513", + "node_id": "dailycode-4b8e2ba0678440539ca1fc73c8852103", "keywords": [], "children": [], "keywords_must": [], @@ -1583,7 +1573,7 @@ }, { "exercises": { - "node_id": "dailycode-9beb2eba588841a6b73e635b2c9fad46", + "node_id": "dailycode-69d51623b58146baa7164733d16a104a", "keywords": [], "children": [], "keywords_must": [], @@ -1592,7 +1582,7 @@ }, { "exercises": { - "node_id": "dailycode-899d89e48f1148048fa4618b855c92cc", + "node_id": "dailycode-f82947171c0b4413b5364fc8d0a9abc2", "keywords": [], "children": [], "keywords_must": [], @@ -1601,7 +1591,7 @@ }, { "exercises": { - "node_id": "dailycode-4047f84489c9453eb082e3e15cf6ad39", + "node_id": "dailycode-4a30eebe19474c4fb0a387ab45a684de", "keywords": [], "children": [], "keywords_must": [], @@ -1610,7 +1600,7 @@ }, { "exercises": { - "node_id": "dailycode-45ad704b5bf2410f91065df96249a035", + "node_id": "dailycode-2ab0d6770e5f46889d71ba2f4b2e1fb1", "keywords": [], "children": [], "keywords_must": [], @@ -1619,7 +1609,7 @@ }, { "exercises": { - "node_id": "dailycode-cc53b8c00c3b47e49acec679ed77a9a8", + "node_id": "dailycode-df2108c0132f4f87a1db8b491de4dc79", "keywords": [], "children": [], "keywords_must": [], @@ -1628,7 +1618,7 @@ }, { "exercises": { - "node_id": "dailycode-cd394beaa1464dbbac796050086c3f6c", + "node_id": "dailycode-3cd29560f5674e679333d243e81115c0", "keywords": [], "children": [], "keywords_must": [], @@ -1637,7 +1627,7 @@ }, { "exercises": { - "node_id": "dailycode-dd6c58cbe89a48799101af843c45a7c4", + "node_id": "dailycode-cd10c107bc354eef83e1b81a46b78db5", "keywords": [], "children": [], "keywords_must": [], @@ -1646,7 +1636,7 @@ }, { "exercises": { - "node_id": "dailycode-f46ab61031ab4af6926cc6db067d1b78", + "node_id": "dailycode-77f941ad05c44053af905fd80f942bd5", "keywords": [], "children": [], "keywords_must": [], @@ -1655,7 +1645,7 @@ }, { "exercises": { - "node_id": "dailycode-bb67ad165b7640ba9bc5888f3d4a2647", + "node_id": "dailycode-00a267eca7a84efdac846774beeb5766", "keywords": [], "children": [], "keywords_must": [], @@ -1664,7 +1654,7 @@ }, { "exercises": { - "node_id": "dailycode-8d314c28e1e44f6e8b8c85d1ddc064fb", + "node_id": "dailycode-a0ba50f39b734de284a9d868affd00a5", "keywords": [], "children": [], "keywords_must": [], @@ -1673,16 +1663,26 @@ }, { "exercises": { - "node_id": "dailycode-40b9002d2beb42aeabf9947bc8af5932", + "node_id": "dailycode-d1b9ca19b0a24258833ae33eac8f8ee6", "keywords": [], "children": [], "keywords_must": [], "keywords_forbid": [] } - }, + } + ], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "python": { + "node_id": "dailycode-5219545f25234c5cad33fc2f95fd7880", + "keywords": [], + "children": [ { "exercises": { - "node_id": "dailycode-97cf74ce017444f1aa65cfa6a8ae7451", + "node_id": "dailycode-2eebebfff6fa4188a9711c043407e25f", "keywords": [], "children": [], "keywords_must": [], @@ -1691,7 +1691,7 @@ }, { "exercises": { - "node_id": "dailycode-7f49212df36b49e78915b9f27d2c4387", + "node_id": "dailycode-d23a2d27d45a49b197d1cd6eea72f56a", "keywords": [], "children": [], "keywords_must": [], @@ -1700,7 +1700,7 @@ }, { "exercises": { - "node_id": "dailycode-5ca24290c093492b987b122e8cb2acd8", + "node_id": "dailycode-6d903ddd2bbf4473b7d0e9d6c0b0c2c8", "keywords": [], "children": [], "keywords_must": [], @@ -1709,7 +1709,7 @@ }, { "exercises": { - "node_id": "dailycode-2c643620e7db4198b4799fb816be0bf9", + "node_id": "dailycode-32ce873ede9141efaa8c63975adf1561", "keywords": [], "children": [], "keywords_must": [], @@ -1718,7 +1718,7 @@ }, { "exercises": { - "node_id": "dailycode-5bdf8ba742d641e29ecca718a5fcaab6", + "node_id": "dailycode-94df85e9dbd04a8cb60cec11aa9b170a", "keywords": [], "children": [], "keywords_must": [], @@ -1727,7 +1727,7 @@ }, { "exercises": { - "node_id": "dailycode-d5d81e058c794c00ad9824c7649d4168", + "node_id": "dailycode-2e6302bf718d46598da5024957c605a0", "keywords": [], "children": [], "keywords_must": [], @@ -1736,7 +1736,7 @@ }, { "exercises": { - "node_id": "dailycode-8c71087921b345cd8aceed9913f3cea3", + "node_id": "dailycode-37725ca16b9f48d7a618ebe5d654955d", "keywords": [], "children": [], "keywords_must": [], @@ -1745,7 +1745,7 @@ }, { "exercises": { - "node_id": "dailycode-9290d8e155064971b7dac798bc6e3b30", + "node_id": "dailycode-eb8c1b6d542e4aa6aa9b722336978115", "keywords": [], "children": [], "keywords_must": [], @@ -1754,7 +1754,7 @@ }, { "exercises": { - "node_id": "dailycode-87c05af61eca47f899c58a92805fb9db", + "node_id": "dailycode-0e465e8d70a1454a8aac9dd2da5f9325", "keywords": [], "children": [], "keywords_must": [], @@ -1763,26 +1763,16 @@ }, { "exercises": { - "node_id": "dailycode-c4157a6e02994060aa622e2fb33eda35", + "node_id": "dailycode-95f5fc9c54d0497ab2c97dd8c49b8629", "keywords": [], "children": [], "keywords_must": [], "keywords_forbid": [] } - } - ], - "keywords_must": [], - "keywords_forbid": [] - } - }, - { - "it_knowledge": { - "node_id": "dailycode-3b3dafe8cf4d4c018cf368ec5b10a7d7", - "keywords": [], - "children": [ + }, { "exercises": { - "node_id": "dailycode-7d322d7680364e9eb8bd499d459b5830", + "node_id": "dailycode-4e18b0172b18463dadaf46362740d7d0", "keywords": [], "children": [], "keywords_must": [], @@ -1791,7 +1781,7 @@ }, { "exercises": { - "node_id": "dailycode-fda12588f1f240ba9e6a0d68a5988930", + "node_id": "dailycode-2bef970158ef4ce2bc686d63ee943610", "keywords": [], "children": [], "keywords_must": [], @@ -1800,7 +1790,7 @@ }, { "exercises": { - "node_id": "dailycode-4f67dc4da72a41f6b12c2ea744c12dda", + "node_id": "dailycode-d722f2ee79964c4ba0ff10be006ed793", "keywords": [], "children": [], "keywords_must": [], @@ -1809,7 +1799,7 @@ }, { "exercises": { - "node_id": "dailycode-d27e122b8e6b406383a640fe29f0d801", + "node_id": "dailycode-5e0a54189fd843a8954fa9ae5aac50a0", "keywords": [], "children": [], "keywords_must": [], @@ -1818,7 +1808,7 @@ }, { "exercises": { - "node_id": "dailycode-d532c487ab864bf2b1a89733541daa2a", + "node_id": "dailycode-a9142d5aeaa848daac6817cae5a08bb1", "keywords": [], "children": [], "keywords_must": [], @@ -1827,7 +1817,7 @@ }, { "exercises": { - "node_id": "dailycode-6db64e6fef8c41979a0e555a73904772", + "node_id": "dailycode-b3bc51803cda4223ad95594ff9597d61", "keywords": [], "children": [], "keywords_must": [], @@ -1836,7 +1826,7 @@ }, { "exercises": { - "node_id": "dailycode-ae3f4c23378d488fae3eef5e1ea5b9d6", + "node_id": "dailycode-be86731880ca4fb99657c3f64cd64235", "keywords": [], "children": [], "keywords_must": [], @@ -1845,7 +1835,7 @@ }, { "exercises": { - "node_id": "dailycode-c1e34791df744e9aa80e2170f6165279", + "node_id": "dailycode-a348977e517f4b358abaf20c42988cbf", "keywords": [], "children": [], "keywords_must": [], @@ -1854,7 +1844,7 @@ }, { "exercises": { - "node_id": "dailycode-e8bc1d68ff894091b1bcce5f3902fd77", + "node_id": "dailycode-495106c5ee4543a98d00295b797e3982", "keywords": [], "children": [], "keywords_must": [], @@ -1863,7 +1853,7 @@ }, { "exercises": { - "node_id": "dailycode-d830455981d94370b9c1d8818f9be557", + "node_id": "dailycode-654c59b4c5de4a82af30051c65b06181", "keywords": [], "children": [], "keywords_must": [], @@ -1872,7 +1862,7 @@ }, { "exercises": { - "node_id": "dailycode-5768a004640642f4a6d8ad05da14c6ee", + "node_id": "dailycode-1dc9532947e14e2aaa9274f1ba3e093e", "keywords": [], "children": [], "keywords_must": [], @@ -1881,7 +1871,7 @@ }, { "exercises": { - "node_id": "dailycode-6bbef4141e7a49a4bdf572a75f0da5a6", + "node_id": "dailycode-bb13d528854f425581da02db1f7f053b", "keywords": [], "children": [], "keywords_must": [], @@ -1890,7 +1880,7 @@ }, { "exercises": { - "node_id": "dailycode-a4c3a6f260b243dba3a75bbee1ddd3a0", + "node_id": "dailycode-45221df1b0024a78bfef72b49e99492c", "keywords": [], "children": [], "keywords_must": [], @@ -1899,7 +1889,7 @@ }, { "exercises": { - "node_id": "dailycode-cba3c9a6ed1f460ba5b586eb0a232e62", + "node_id": "dailycode-6a1541c03bbf441a9f896331a5d4cba1", "keywords": [], "children": [], "keywords_must": [], @@ -1908,7 +1898,7 @@ }, { "exercises": { - "node_id": "dailycode-84c9b65036c845e8a77148e5f344a4b7", + "node_id": "dailycode-5d456f7d55404cf799b24bcc882a1553", "keywords": [], "children": [], "keywords_must": [], @@ -1917,7 +1907,7 @@ }, { "exercises": { - "node_id": "dailycode-9b16c89cbe7e434aad1c5465eb2b6da9", + "node_id": "dailycode-309fe024bfc848f0b91a68fe6b953057", "keywords": [], "children": [], "keywords_must": [], @@ -1926,7 +1916,7 @@ }, { "exercises": { - "node_id": "dailycode-0d3635aab75f48beabfddb5726669e18", + "node_id": "dailycode-286abc7bb8fd4a43bba78b881258b513", "keywords": [], "children": [], "keywords_must": [], @@ -1935,7 +1925,7 @@ }, { "exercises": { - "node_id": "dailycode-ebb4b625582b406184b9338718c47c7f", + "node_id": "dailycode-9beb2eba588841a6b73e635b2c9fad46", "keywords": [], "children": [], "keywords_must": [], @@ -1944,7 +1934,7 @@ }, { "exercises": { - "node_id": "dailycode-c4ea7b5d22024757bccb60adbd5ef2ef", + "node_id": "dailycode-899d89e48f1148048fa4618b855c92cc", "keywords": [], "children": [], "keywords_must": [], @@ -1953,7 +1943,7 @@ }, { "exercises": { - "node_id": "dailycode-2dcd0aea6e1e4402aace9e6aa5302c85", + "node_id": "dailycode-4047f84489c9453eb082e3e15cf6ad39", "keywords": [], "children": [], "keywords_must": [], @@ -1962,7 +1952,7 @@ }, { "exercises": { - "node_id": "dailycode-eea138527d38484791eb791963f43112", + "node_id": "dailycode-45ad704b5bf2410f91065df96249a035", "keywords": [], "children": [], "keywords_must": [], @@ -1971,7 +1961,7 @@ }, { "exercises": { - "node_id": "dailycode-3af8b35b6d2d428ea3854f422ee39a39", + "node_id": "dailycode-cc53b8c00c3b47e49acec679ed77a9a8", "keywords": [], "children": [], "keywords_must": [], @@ -1980,7 +1970,7 @@ }, { "exercises": { - "node_id": "dailycode-9d9d7fb673444ab080b7202400e04a7b", + "node_id": "dailycode-cd394beaa1464dbbac796050086c3f6c", "keywords": [], "children": [], "keywords_must": [], @@ -1989,7 +1979,7 @@ }, { "exercises": { - "node_id": "dailycode-1874bb8928ca44d6a48d32b9bf947f1b", + "node_id": "dailycode-dd6c58cbe89a48799101af843c45a7c4", "keywords": [], "children": [], "keywords_must": [], @@ -1998,7 +1988,7 @@ }, { "exercises": { - "node_id": "dailycode-2a111fcaba4341f7a65a09a7ede5a48c", + "node_id": "dailycode-f46ab61031ab4af6926cc6db067d1b78", "keywords": [], "children": [], "keywords_must": [], @@ -2007,7 +1997,7 @@ }, { "exercises": { - "node_id": "dailycode-20e735ce3b6940bbac5869f49fa2ffae", + "node_id": "dailycode-bb67ad165b7640ba9bc5888f3d4a2647", "keywords": [], "children": [], "keywords_must": [], @@ -2016,7 +2006,7 @@ }, { "exercises": { - "node_id": "dailycode-82042adf0ebe41d2afb1c38e03eae895", + "node_id": "dailycode-8d314c28e1e44f6e8b8c85d1ddc064fb", "keywords": [], "children": [], "keywords_must": [], @@ -2025,7 +2015,7 @@ }, { "exercises": { - "node_id": "dailycode-ed83b0d2e44b4b3b9792ffdc3edc7c82", + "node_id": "dailycode-40b9002d2beb42aeabf9947bc8af5932", "keywords": [], "children": [], "keywords_must": [], @@ -2034,7 +2024,7 @@ }, { "exercises": { - "node_id": "dailycode-645f76afea594faf899ac96fed1d29b7", + "node_id": "dailycode-97cf74ce017444f1aa65cfa6a8ae7451", "keywords": [], "children": [], "keywords_must": [], @@ -2043,7 +2033,7 @@ }, { "exercises": { - "node_id": "dailycode-f1bc4c2a0701401a867657c88bfd47e9", + "node_id": "dailycode-7f49212df36b49e78915b9f27d2c4387", "keywords": [], "children": [], "keywords_must": [], @@ -2052,7 +2042,7 @@ }, { "exercises": { - "node_id": "dailycode-7dbb8f79dec54d63917d654a988af3d6", + "node_id": "dailycode-5ca24290c093492b987b122e8cb2acd8", "keywords": [], "children": [], "keywords_must": [], @@ -2061,7 +2051,7 @@ }, { "exercises": { - "node_id": "dailycode-43ec2f7700d443ef860de334584a26e5", + "node_id": "dailycode-2c643620e7db4198b4799fb816be0bf9", "keywords": [], "children": [], "keywords_must": [], @@ -2070,7 +2060,7 @@ }, { "exercises": { - "node_id": "dailycode-5ec33b3b364b406e87fcc94a91078a77", + "node_id": "dailycode-5bdf8ba742d641e29ecca718a5fcaab6", "keywords": [], "children": [], "keywords_must": [], @@ -2079,7 +2069,7 @@ }, { "exercises": { - "node_id": "dailycode-6f46c79e24064da68c8274135b4e7bb2", + "node_id": "dailycode-d5d81e058c794c00ad9824c7649d4168", "keywords": [], "children": [], "keywords_must": [], @@ -2088,7 +2078,7 @@ }, { "exercises": { - "node_id": "dailycode-2662cb46d3c74a52845c31c044f25d64", + "node_id": "dailycode-8c71087921b345cd8aceed9913f3cea3", "keywords": [], "children": [], "keywords_must": [], @@ -2097,7 +2087,7 @@ }, { "exercises": { - "node_id": "dailycode-fa9ed9743c364d24864df3456b151572", + "node_id": "dailycode-9290d8e155064971b7dac798bc6e3b30", "keywords": [], "children": [], "keywords_must": [], @@ -2106,7 +2096,7 @@ }, { "exercises": { - "node_id": "dailycode-b92c284f681b44608a543e612537b351", + "node_id": "dailycode-87c05af61eca47f899c58a92805fb9db", "keywords": [], "children": [], "keywords_must": [], @@ -2115,16 +2105,26 @@ }, { "exercises": { - "node_id": "dailycode-1f7abd44fd63465f90d5874249906d97", + "node_id": "dailycode-c4157a6e02994060aa622e2fb33eda35", "keywords": [], "children": [], "keywords_must": [], "keywords_forbid": [] } - }, + } + ], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "it_knowledge": { + "node_id": "dailycode-3b3dafe8cf4d4c018cf368ec5b10a7d7", + "keywords": [], + "children": [ { "exercises": { - "node_id": "dailycode-1ab4e305968f4caeab0af3453504084f", + "node_id": "dailycode-7d322d7680364e9eb8bd499d459b5830", "keywords": [], "children": [], "keywords_must": [], @@ -2133,7 +2133,7 @@ }, { "exercises": { - "node_id": "dailycode-de7ff98a55c4460cada3f34683a4681e", + "node_id": "dailycode-fda12588f1f240ba9e6a0d68a5988930", "keywords": [], "children": [], "keywords_must": [], @@ -2142,7 +2142,7 @@ }, { "exercises": { - "node_id": "dailycode-7ce70a8d2a144e0d93c8d243a3eba9e1", + "node_id": "dailycode-4f67dc4da72a41f6b12c2ea744c12dda", "keywords": [], "children": [], "keywords_must": [], @@ -2151,7 +2151,7 @@ }, { "exercises": { - "node_id": "dailycode-7ec5c3aa458e4858b4b6b40ef7912f62", + "node_id": "dailycode-d27e122b8e6b406383a640fe29f0d801", "keywords": [], "children": [], "keywords_must": [], @@ -2160,7 +2160,7 @@ }, { "exercises": { - "node_id": "dailycode-5daa7f0d16044577887902bb1d7fe631", + "node_id": "dailycode-d532c487ab864bf2b1a89733541daa2a", "keywords": [], "children": [], "keywords_must": [], @@ -2169,7 +2169,7 @@ }, { "exercises": { - "node_id": "dailycode-2ad04575e5514b26b1fa814eb860c470", + "node_id": "dailycode-6db64e6fef8c41979a0e555a73904772", "keywords": [], "children": [], "keywords_must": [], @@ -2178,7 +2178,7 @@ }, { "exercises": { - "node_id": "dailycode-76f76e1c35fe4e8bb39c9b74184ca7b6", + "node_id": "dailycode-ae3f4c23378d488fae3eef5e1ea5b9d6", "keywords": [], "children": [], "keywords_must": [], @@ -2187,7 +2187,7 @@ }, { "exercises": { - "node_id": "dailycode-8d92677f51f148debc7fab5c5580c0c1", + "node_id": "dailycode-c1e34791df744e9aa80e2170f6165279", "keywords": [], "children": [], "keywords_must": [], @@ -2196,7 +2196,7 @@ }, { "exercises": { - "node_id": "dailycode-bf70aecc1ea446cbb690ee7b999f5464", + "node_id": "dailycode-e8bc1d68ff894091b1bcce5f3902fd77", "keywords": [], "children": [], "keywords_must": [], @@ -2205,7 +2205,7 @@ }, { "exercises": { - "node_id": "dailycode-98c411255a4a4cb19daf3b8c4b26f169", + "node_id": "dailycode-d830455981d94370b9c1d8818f9be557", "keywords": [], "children": [], "keywords_must": [], @@ -2214,7 +2214,7 @@ }, { "exercises": { - "node_id": "dailycode-70f7f6a456bb462dbb55aeecadadf626", + "node_id": "dailycode-5768a004640642f4a6d8ad05da14c6ee", "keywords": [], "children": [], "keywords_must": [], @@ -2223,7 +2223,7 @@ }, { "exercises": { - "node_id": "dailycode-12a2e7d208a34209ae453b06633584d4", + "node_id": "dailycode-6bbef4141e7a49a4bdf572a75f0da5a6", "keywords": [], "children": [], "keywords_must": [], @@ -2232,7 +2232,7 @@ }, { "exercises": { - "node_id": "dailycode-3a4af76d4d6348139205ea2b8874fbe6", + "node_id": "dailycode-a4c3a6f260b243dba3a75bbee1ddd3a0", "keywords": [], "children": [], "keywords_must": [], @@ -2241,7 +2241,7 @@ }, { "exercises": { - "node_id": "dailycode-d689d8cd98cf4c6ab0db382d775cf3f8", + "node_id": "dailycode-cba3c9a6ed1f460ba5b586eb0a232e62", "keywords": [], "children": [], "keywords_must": [], @@ -2250,7 +2250,7 @@ }, { "exercises": { - "node_id": "dailycode-b1f359376f0948de9214b9a9114c983b", + "node_id": "dailycode-84c9b65036c845e8a77148e5f344a4b7", "keywords": [], "children": [], "keywords_must": [], @@ -2259,7 +2259,7 @@ }, { "exercises": { - "node_id": "dailycode-4e899355f25e44f3bd5411bbafe1db2f", + "node_id": "dailycode-9b16c89cbe7e434aad1c5465eb2b6da9", "keywords": [], "children": [], "keywords_must": [], @@ -2268,7 +2268,7 @@ }, { "exercises": { - "node_id": "dailycode-162687a20eff465e9380c51be73134aa", + "node_id": "dailycode-0d3635aab75f48beabfddb5726669e18", "keywords": [], "children": [], "keywords_must": [], @@ -2277,7 +2277,7 @@ }, { "exercises": { - "node_id": "dailycode-d4ca484c2c2c4851ae05f24efa69387a", + "node_id": "dailycode-ebb4b625582b406184b9338718c47c7f", "keywords": [], "children": [], "keywords_must": [], @@ -2286,7 +2286,7 @@ }, { "exercises": { - "node_id": "dailycode-3f3d19b3a7dd432780f957e0e72457c1", + "node_id": "dailycode-c4ea7b5d22024757bccb60adbd5ef2ef", "keywords": [], "children": [], "keywords_must": [], @@ -2295,7 +2295,7 @@ }, { "exercises": { - "node_id": "dailycode-9cba35f3c300452c8ff82045b0fbfe6f", + "node_id": "dailycode-2dcd0aea6e1e4402aace9e6aa5302c85", "keywords": [], "children": [], "keywords_must": [], @@ -2304,7 +2304,7 @@ }, { "exercises": { - "node_id": "dailycode-7359c47192094def92008a17778d76bf", + "node_id": "dailycode-eea138527d38484791eb791963f43112", "keywords": [], "children": [], "keywords_must": [], @@ -2313,7 +2313,7 @@ }, { "exercises": { - "node_id": "dailycode-a6e79afb743b483d86f9e071f878b420", + "node_id": "dailycode-3af8b35b6d2d428ea3854f422ee39a39", "keywords": [], "children": [], "keywords_must": [], @@ -2322,7 +2322,7 @@ }, { "exercises": { - "node_id": "dailycode-30cd8f8325714a92982bd2cf0630afc4", + "node_id": "dailycode-9d9d7fb673444ab080b7202400e04a7b", "keywords": [], "children": [], "keywords_must": [], @@ -2331,7 +2331,7 @@ }, { "exercises": { - "node_id": "dailycode-7881e4a81e864c7bac1abf1e2bdf4da2", + "node_id": "dailycode-1874bb8928ca44d6a48d32b9bf947f1b", "keywords": [], "children": [], "keywords_must": [], @@ -2340,7 +2340,7 @@ }, { "exercises": { - "node_id": "dailycode-0624b49dc8e44aadb007ba6d2715c137", + "node_id": "dailycode-2a111fcaba4341f7a65a09a7ede5a48c", "keywords": [], "children": [], "keywords_must": [], @@ -2349,7 +2349,7 @@ }, { "exercises": { - "node_id": "dailycode-a6d8223f903a4e40ab87582765198156", + "node_id": "dailycode-20e735ce3b6940bbac5869f49fa2ffae", "keywords": [], "children": [], "keywords_must": [], @@ -2358,7 +2358,7 @@ }, { "exercises": { - "node_id": "dailycode-251b5a16ba714934a8a7fa216307fa6d", + "node_id": "dailycode-82042adf0ebe41d2afb1c38e03eae895", "keywords": [], "children": [], "keywords_must": [], @@ -2367,7 +2367,7 @@ }, { "exercises": { - "node_id": "dailycode-97b847e683774717bd5cce6bf5c6f009", + "node_id": "dailycode-ed83b0d2e44b4b3b9792ffdc3edc7c82", "keywords": [], "children": [], "keywords_must": [], @@ -2376,7 +2376,7 @@ }, { "exercises": { - "node_id": "dailycode-dbfc9553f0754363921f59cf92d01440", + "node_id": "dailycode-645f76afea594faf899ac96fed1d29b7", "keywords": [], "children": [], "keywords_must": [], @@ -2385,7 +2385,7 @@ }, { "exercises": { - "node_id": "dailycode-6e51f330d8694426add5c311f6ceef7b", + "node_id": "dailycode-f1bc4c2a0701401a867657c88bfd47e9", "keywords": [], "children": [], "keywords_must": [], @@ -2394,7 +2394,7 @@ }, { "exercises": { - "node_id": "dailycode-a4e1e718a2454c02acf68d29536aeb0e", + "node_id": "dailycode-7dbb8f79dec54d63917d654a988af3d6", "keywords": [], "children": [], "keywords_must": [], @@ -2403,7 +2403,7 @@ }, { "exercises": { - "node_id": "dailycode-6f559fe983984cfa972d8898e37d9e65", + "node_id": "dailycode-43ec2f7700d443ef860de334584a26e5", "keywords": [], "children": [], "keywords_must": [], @@ -2412,7 +2412,7 @@ }, { "exercises": { - "node_id": "dailycode-5090ab3ccc5b43cfaec61d71920b575c", + "node_id": "dailycode-5ec33b3b364b406e87fcc94a91078a77", "keywords": [], "children": [], "keywords_must": [], @@ -2421,7 +2421,7 @@ }, { "exercises": { - "node_id": "dailycode-d4f63b8f23874b9c8f7a5a8cd91dcbe7", + "node_id": "dailycode-6f46c79e24064da68c8274135b4e7bb2", "keywords": [], "children": [], "keywords_must": [], @@ -2430,7 +2430,7 @@ }, { "exercises": { - "node_id": "dailycode-77a791d530dc402db72d691e6b89d3c3", + "node_id": "dailycode-2662cb46d3c74a52845c31c044f25d64", "keywords": [], "children": [], "keywords_must": [], @@ -2439,7 +2439,7 @@ }, { "exercises": { - "node_id": "dailycode-a48d3d86c52344df91d358ecd2f8f63f", + "node_id": "dailycode-fa9ed9743c364d24864df3456b151572", "keywords": [], "children": [], "keywords_must": [], @@ -2448,7 +2448,7 @@ }, { "exercises": { - "node_id": "dailycode-274f3810ac424f81b3b6db4196775141", + "node_id": "dailycode-b92c284f681b44608a543e612537b351", "keywords": [], "children": [], "keywords_must": [], @@ -2457,7 +2457,7 @@ }, { "exercises": { - "node_id": "dailycode-32c5d067cfda4c76964bd82da5387288", + "node_id": "dailycode-1f7abd44fd63465f90d5874249906d97", "keywords": [], "children": [], "keywords_must": [], @@ -2466,7 +2466,7 @@ }, { "exercises": { - "node_id": "dailycode-89f52ebc8a4b47739d97a12253077695", + "node_id": "dailycode-1ab4e305968f4caeab0af3453504084f", "keywords": [], "children": [], "keywords_must": [], @@ -2475,7 +2475,7 @@ }, { "exercises": { - "node_id": "dailycode-ee85ae278fd44d9da846fbbf5ed4c7a4", + "node_id": "dailycode-de7ff98a55c4460cada3f34683a4681e", "keywords": [], "children": [], "keywords_must": [], @@ -2484,7 +2484,7 @@ }, { "exercises": { - "node_id": "dailycode-c0aed0c58957433cb8f1868a22055cfb", + "node_id": "dailycode-7ce70a8d2a144e0d93c8d243a3eba9e1", "keywords": [], "children": [], "keywords_must": [], @@ -2493,7 +2493,7 @@ }, { "exercises": { - "node_id": "dailycode-9a0780174e694f9bbe241fd378e0562e", + "node_id": "dailycode-7ec5c3aa458e4858b4b6b40ef7912f62", "keywords": [], "children": [], "keywords_must": [], @@ -2502,7 +2502,7 @@ }, { "exercises": { - "node_id": "dailycode-01b9b605fcb04130aef43a9bb66e220d", + "node_id": "dailycode-5daa7f0d16044577887902bb1d7fe631", "keywords": [], "children": [], "keywords_must": [], @@ -2511,7 +2511,7 @@ }, { "exercises": { - "node_id": "dailycode-f4e17b152b314f12900cb6e56461075e", + "node_id": "dailycode-2ad04575e5514b26b1fa814eb860c470", "keywords": [], "children": [], "keywords_must": [], @@ -2520,7 +2520,7 @@ }, { "exercises": { - "node_id": "dailycode-87e44019fa8e4b3b96f8d574f854c559", + "node_id": "dailycode-76f76e1c35fe4e8bb39c9b74184ca7b6", "keywords": [], "children": [], "keywords_must": [], @@ -2529,7 +2529,7 @@ }, { "exercises": { - "node_id": "dailycode-9b6195cf8bcc4bc68defa82c9d54710c", + "node_id": "dailycode-8d92677f51f148debc7fab5c5580c0c1", "keywords": [], "children": [], "keywords_must": [], @@ -2538,7 +2538,7 @@ }, { "exercises": { - "node_id": "dailycode-5970022817174efd8c186ac98355e556", + "node_id": "dailycode-bf70aecc1ea446cbb690ee7b999f5464", "keywords": [], "children": [], "keywords_must": [], @@ -2547,7 +2547,7 @@ }, { "exercises": { - "node_id": "dailycode-0aa83a4f75ec442f985f2804991a6f9e", + "node_id": "dailycode-98c411255a4a4cb19daf3b8c4b26f169", "keywords": [], "children": [], "keywords_must": [], @@ -2556,7 +2556,7 @@ }, { "exercises": { - "node_id": "dailycode-697ff18599bb4706827ddd35c5894dfa", + "node_id": "dailycode-70f7f6a456bb462dbb55aeecadadf626", "keywords": [], "children": [], "keywords_must": [], @@ -2565,7 +2565,7 @@ }, { "exercises": { - "node_id": "dailycode-d8ecab5a68b24f72a87ed9eb9d4c3eb1", + "node_id": "dailycode-12a2e7d208a34209ae453b06633584d4", "keywords": [], "children": [], "keywords_must": [], @@ -2574,7 +2574,7 @@ }, { "exercises": { - "node_id": "dailycode-00dac97bf0af46d4b20e08f62b95a31c", + "node_id": "dailycode-3a4af76d4d6348139205ea2b8874fbe6", "keywords": [], "children": [], "keywords_must": [], @@ -2583,7 +2583,7 @@ }, { "exercises": { - "node_id": "dailycode-29e3d0033a9e467f84bb1a11d9469f4e", + "node_id": "dailycode-d689d8cd98cf4c6ab0db382d775cf3f8", "keywords": [], "children": [], "keywords_must": [], @@ -2592,7 +2592,7 @@ }, { "exercises": { - "node_id": "dailycode-0e6c90044ce443ae98492ad6dd571771", + "node_id": "dailycode-b1f359376f0948de9214b9a9114c983b", "keywords": [], "children": [], "keywords_must": [], @@ -2601,7 +2601,7 @@ }, { "exercises": { - "node_id": "dailycode-052601f2bab7422b910fb2099fe48ecf", + "node_id": "dailycode-4e899355f25e44f3bd5411bbafe1db2f", "keywords": [], "children": [], "keywords_must": [], @@ -2610,7 +2610,7 @@ }, { "exercises": { - "node_id": "dailycode-be4e2071c24b48578065de9eadb4beea", + "node_id": "dailycode-162687a20eff465e9380c51be73134aa", "keywords": [], "children": [], "keywords_must": [], @@ -2619,7 +2619,7 @@ }, { "exercises": { - "node_id": "dailycode-6f2accb7ee4047be818220aa04bffc98", + "node_id": "dailycode-d4ca484c2c2c4851ae05f24efa69387a", "keywords": [], "children": [], "keywords_must": [], @@ -2628,7 +2628,7 @@ }, { "exercises": { - "node_id": "dailycode-546b01ceba0b4ed7b4110b7b54f5dea2", + "node_id": "dailycode-3f3d19b3a7dd432780f957e0e72457c1", "keywords": [], "children": [], "keywords_must": [], @@ -2637,7 +2637,7 @@ }, { "exercises": { - "node_id": "dailycode-aea1e1a0b8194ca3a4e4a6d499734159", + "node_id": "dailycode-9cba35f3c300452c8ff82045b0fbfe6f", "keywords": [], "children": [], "keywords_must": [], @@ -2646,7 +2646,7 @@ }, { "exercises": { - "node_id": "dailycode-9d17dc8bf5a948ccab1eb31f11d0c4c5", + "node_id": "dailycode-7359c47192094def92008a17778d76bf", "keywords": [], "children": [], "keywords_must": [], @@ -2655,7 +2655,7 @@ }, { "exercises": { - "node_id": "dailycode-07916c627dea406983fa4f459e35bb3c", + "node_id": "dailycode-a6e79afb743b483d86f9e071f878b420", "keywords": [], "children": [], "keywords_must": [], @@ -2664,7 +2664,7 @@ }, { "exercises": { - "node_id": "dailycode-8235273c8c81448fb35275281f81d775", + "node_id": "dailycode-30cd8f8325714a92982bd2cf0630afc4", "keywords": [], "children": [], "keywords_must": [], @@ -2673,7 +2673,7 @@ }, { "exercises": { - "node_id": "dailycode-6bfa7f2885694ab09f5b71d25d15bc31", + "node_id": "dailycode-7881e4a81e864c7bac1abf1e2bdf4da2", "keywords": [], "children": [], "keywords_must": [], @@ -2682,7 +2682,7 @@ }, { "exercises": { - "node_id": "dailycode-70e64d37dbd04624a69892967e525415", + "node_id": "dailycode-0624b49dc8e44aadb007ba6d2715c137", "keywords": [], "children": [], "keywords_must": [], @@ -2691,7 +2691,7 @@ }, { "exercises": { - "node_id": "dailycode-0a97930729d84311a82d05cfe4c18d5d", + "node_id": "dailycode-a6d8223f903a4e40ab87582765198156", "keywords": [], "children": [], "keywords_must": [], @@ -2700,7 +2700,7 @@ }, { "exercises": { - "node_id": "dailycode-8afbcaa167c84350ac71132140fde05b", + "node_id": "dailycode-251b5a16ba714934a8a7fa216307fa6d", "keywords": [], "children": [], "keywords_must": [], @@ -2709,7 +2709,7 @@ }, { "exercises": { - "node_id": "dailycode-3a783139b7ba4b52a74504f1d6b9e7a6", + "node_id": "dailycode-97b847e683774717bd5cce6bf5c6f009", "keywords": [], "children": [], "keywords_must": [], @@ -2718,7 +2718,7 @@ }, { "exercises": { - "node_id": "dailycode-bba8567100b848aa82758c9418d5ccb4", + "node_id": "dailycode-dbfc9553f0754363921f59cf92d01440", "keywords": [], "children": [], "keywords_must": [], @@ -2727,7 +2727,7 @@ }, { "exercises": { - "node_id": "dailycode-32bac8dac5b34f89b5b8dc75a5f19a39", + "node_id": "dailycode-6e51f330d8694426add5c311f6ceef7b", "keywords": [], "children": [], "keywords_must": [], @@ -2736,7 +2736,7 @@ }, { "exercises": { - "node_id": "dailycode-66ae2b099d834c8099498690e23e33b5", + "node_id": "dailycode-a4e1e718a2454c02acf68d29536aeb0e", "keywords": [], "children": [], "keywords_must": [], @@ -2745,7 +2745,7 @@ }, { "exercises": { - "node_id": "dailycode-4823423c35904fa6a0ddfd45633d121a", + "node_id": "dailycode-6f559fe983984cfa972d8898e37d9e65", "keywords": [], "children": [], "keywords_must": [], @@ -2754,7 +2754,7 @@ }, { "exercises": { - "node_id": "dailycode-3a9f92c52bf84b58a49300c02440e873", + "node_id": "dailycode-5090ab3ccc5b43cfaec61d71920b575c", "keywords": [], "children": [], "keywords_must": [], @@ -2763,7 +2763,7 @@ }, { "exercises": { - "node_id": "dailycode-ac5ed4f8ae2f4472b1affae297154297", + "node_id": "dailycode-d4f63b8f23874b9c8f7a5a8cd91dcbe7", "keywords": [], "children": [], "keywords_must": [], @@ -2772,7 +2772,7 @@ }, { "exercises": { - "node_id": "dailycode-e90481fb818140499b31d4e2fb89030a", + "node_id": "dailycode-77a791d530dc402db72d691e6b89d3c3", "keywords": [], "children": [], "keywords_must": [], @@ -2781,7 +2781,7 @@ }, { "exercises": { - "node_id": "dailycode-91aec32565404ada885c69484e07cdf7", + "node_id": "dailycode-a48d3d86c52344df91d358ecd2f8f63f", "keywords": [], "children": [], "keywords_must": [], @@ -2790,7 +2790,7 @@ }, { "exercises": { - "node_id": "dailycode-576a315c842d4532a7c7bf50d6959e6f", + "node_id": "dailycode-274f3810ac424f81b3b6db4196775141", "keywords": [], "children": [], "keywords_must": [], @@ -2799,7 +2799,7 @@ }, { "exercises": { - "node_id": "dailycode-ef34eb67dcad4a5f9aa32db77c403dbf", + "node_id": "dailycode-32c5d067cfda4c76964bd82da5387288", "keywords": [], "children": [], "keywords_must": [], @@ -2808,7 +2808,7 @@ }, { "exercises": { - "node_id": "dailycode-6e7b717f6010462498251c4fc040d65b", + "node_id": "dailycode-89f52ebc8a4b47739d97a12253077695", "keywords": [], "children": [], "keywords_must": [], @@ -2817,7 +2817,7 @@ }, { "exercises": { - "node_id": "dailycode-0d61911ed2b64af190374590d9aed4c2", + "node_id": "dailycode-ee85ae278fd44d9da846fbbf5ed4c7a4", "keywords": [], "children": [], "keywords_must": [], @@ -2826,7 +2826,7 @@ }, { "exercises": { - "node_id": "dailycode-90e6d52761784f3686465c29d66e8bec", + "node_id": "dailycode-c0aed0c58957433cb8f1868a22055cfb", "keywords": [], "children": [], "keywords_must": [], @@ -2835,7 +2835,7 @@ }, { "exercises": { - "node_id": "dailycode-82723b84b5a94104b7ed0c881440bfa9", + "node_id": "dailycode-9a0780174e694f9bbe241fd378e0562e", "keywords": [], "children": [], "keywords_must": [], @@ -2844,7 +2844,7 @@ }, { "exercises": { - "node_id": "dailycode-beab9431f7d04245861e1fbb377781dd", + "node_id": "dailycode-01b9b605fcb04130aef43a9bb66e220d", "keywords": [], "children": [], "keywords_must": [], @@ -2853,7 +2853,7 @@ }, { "exercises": { - "node_id": "dailycode-99416f041f1c44cca0eccdde38162f93", + "node_id": "dailycode-f4e17b152b314f12900cb6e56461075e", "keywords": [], "children": [], "keywords_must": [], @@ -2862,7 +2862,7 @@ }, { "exercises": { - "node_id": "dailycode-aea5f678498047fc8613899dc318b3e1", + "node_id": "dailycode-87e44019fa8e4b3b96f8d574f854c559", "keywords": [], "children": [], "keywords_must": [], @@ -2871,7 +2871,7 @@ }, { "exercises": { - "node_id": "dailycode-3a74e6bda85041e7be7be316ef6133b0", + "node_id": "dailycode-9b6195cf8bcc4bc68defa82c9d54710c", "keywords": [], "children": [], "keywords_must": [], @@ -2880,7 +2880,7 @@ }, { "exercises": { - "node_id": "dailycode-83d408a356624bf9abdd847a57b1cf7b", + "node_id": "dailycode-5970022817174efd8c186ac98355e556", "keywords": [], "children": [], "keywords_must": [], @@ -2889,7 +2889,7 @@ }, { "exercises": { - "node_id": "dailycode-0f1762276c764c0f947edd773bc3ae21", + "node_id": "dailycode-0aa83a4f75ec442f985f2804991a6f9e", "keywords": [], "children": [], "keywords_must": [], @@ -2898,7 +2898,7 @@ }, { "exercises": { - "node_id": "dailycode-b1f209e9d0f049f590eac7593b027bc6", + "node_id": "dailycode-697ff18599bb4706827ddd35c5894dfa", "keywords": [], "children": [], "keywords_must": [], @@ -2907,7 +2907,7 @@ }, { "exercises": { - "node_id": "dailycode-9298d3080bd74e5cbe1ea002d80e8b74", + "node_id": "dailycode-d8ecab5a68b24f72a87ed9eb9d4c3eb1", "keywords": [], "children": [], "keywords_must": [], @@ -2916,7 +2916,7 @@ }, { "exercises": { - "node_id": "dailycode-282248f320364822915fb7c345db78c6", + "node_id": "dailycode-00dac97bf0af46d4b20e08f62b95a31c", "keywords": [], "children": [], "keywords_must": [], @@ -2925,36 +2925,16 @@ }, { "exercises": { - "node_id": "dailycode-587e137824f94505893b00a7615417c9", + "node_id": "dailycode-29e3d0033a9e467f84bb1a11d9469f4e", "keywords": [], "children": [], "keywords_must": [], "keywords_forbid": [] } - } - ], - "keywords_must": [], - "keywords_forbid": [] - } - } - ], - "keywords_must": [], - "keywords_forbid": [] - } - }, - { - "dailycode中阶": { - "node_id": "dailycode-871ddb4f4fd24afa9e90b909acaa1c20", - "keywords": [], - "children": [ - { - "cpp": { - "node_id": "dailycode-43fd15a13a1f43d08b5d9b72d5a5cedd", - "keywords": [], - "children": [ + }, { "exercises": { - "node_id": "dailycode-ac3df0d6b8e540ac9cfdf9c074c33b33", + "node_id": "dailycode-0e6c90044ce443ae98492ad6dd571771", "keywords": [], "children": [], "keywords_must": [], @@ -2963,7 +2943,7 @@ }, { "exercises": { - "node_id": "dailycode-04771a9a92f54cb1b4125e4528c6a193", + "node_id": "dailycode-052601f2bab7422b910fb2099fe48ecf", "keywords": [], "children": [], "keywords_must": [], @@ -2972,7 +2952,7 @@ }, { "exercises": { - "node_id": "dailycode-e140a9b572594a378231e0b69e615f00", + "node_id": "dailycode-be4e2071c24b48578065de9eadb4beea", "keywords": [], "children": [], "keywords_must": [], @@ -2981,7 +2961,369 @@ }, { "exercises": { - "node_id": "dailycode-fe4cced5cecb47dba951613f6b186850", + "node_id": "dailycode-6f2accb7ee4047be818220aa04bffc98", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-546b01ceba0b4ed7b4110b7b54f5dea2", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-aea1e1a0b8194ca3a4e4a6d499734159", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-9d17dc8bf5a948ccab1eb31f11d0c4c5", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-07916c627dea406983fa4f459e35bb3c", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-8235273c8c81448fb35275281f81d775", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-6bfa7f2885694ab09f5b71d25d15bc31", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-70e64d37dbd04624a69892967e525415", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-0a97930729d84311a82d05cfe4c18d5d", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-8afbcaa167c84350ac71132140fde05b", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-3a783139b7ba4b52a74504f1d6b9e7a6", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-bba8567100b848aa82758c9418d5ccb4", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-32bac8dac5b34f89b5b8dc75a5f19a39", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-66ae2b099d834c8099498690e23e33b5", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-4823423c35904fa6a0ddfd45633d121a", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-3a9f92c52bf84b58a49300c02440e873", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-ac5ed4f8ae2f4472b1affae297154297", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-e90481fb818140499b31d4e2fb89030a", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-91aec32565404ada885c69484e07cdf7", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-576a315c842d4532a7c7bf50d6959e6f", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-ef34eb67dcad4a5f9aa32db77c403dbf", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-6e7b717f6010462498251c4fc040d65b", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-0d61911ed2b64af190374590d9aed4c2", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-90e6d52761784f3686465c29d66e8bec", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-82723b84b5a94104b7ed0c881440bfa9", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-beab9431f7d04245861e1fbb377781dd", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-99416f041f1c44cca0eccdde38162f93", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-aea5f678498047fc8613899dc318b3e1", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-3a74e6bda85041e7be7be316ef6133b0", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-83d408a356624bf9abdd847a57b1cf7b", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-0f1762276c764c0f947edd773bc3ae21", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-b1f209e9d0f049f590eac7593b027bc6", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-9298d3080bd74e5cbe1ea002d80e8b74", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-282248f320364822915fb7c345db78c6", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-587e137824f94505893b00a7615417c9", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + } + ], + "keywords_must": [], + "keywords_forbid": [] + } + } + ], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "dailycode中阶": { + "node_id": "dailycode-871ddb4f4fd24afa9e90b909acaa1c20", + "keywords": [], + "children": [ + { + "cpp": { + "node_id": "dailycode-43fd15a13a1f43d08b5d9b72d5a5cedd", + "keywords": [], + "children": [ + { + "exercises": { + "node_id": "dailycode-ac3df0d6b8e540ac9cfdf9c074c33b33", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-04771a9a92f54cb1b4125e4528c6a193", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-e140a9b572594a378231e0b69e615f00", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-fe4cced5cecb47dba951613f6b186850", "keywords": [], "children": [], "keywords_must": [], @@ -2999,7 +3341,430 @@ }, { "exercises": { - "node_id": "dailycode-a196808cff7b4cd1b5bfbd1d5020ca31", + "node_id": "dailycode-a196808cff7b4cd1b5bfbd1d5020ca31", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-5d88f5aea60b4d6e9dbd83c13e22993f", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-04711f16d9ef4c92a4b8c611f05fa4d4", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-7f4aaca343fc40549296badcaa53bf03", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-5b037f31a3c849158d21cbaed4173fa7", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-ac4ab7abcdeb482bb23684e08a27e9ed", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-df624f99477f4489b3508b5d947545e6", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-a91ab2d4ae12479088f6fe0653c5f877", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-dab42155788f4df992f7bee3d2ceaff3", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-b930e3c023e1440ebb20130a7a2d188b", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-0cef0ea9a9464eb8acb4a439fde7c351", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-707a9a26d46749e9a9e2dde825d0421c", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-f5bede05c3a2454090a4bccc0479462f", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-390b583c367d440f80eaa10524618444", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-2d92b024f38245afa28cec2ec78b78cf", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-d42952ba501a46e5a121004d2f62e724", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-0c1bff5243bc4c4fbb688b0c8e1d1bc0", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-33f647ff549d4301a57cd82b9872bbf8", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-7077b339c1ef498ca92107cbc966a652", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-8159c79d4b6e4544bf44d1f7b9a57ff9", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-d44bd3f0766b4d3b92ff5b5ded112675", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-69ef472d89dd4a86ba769fd50d0ad909", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-022a4daf03b444b1b4fed08a83b469cd", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-22d0c66ac13e492ab38799ba4281480b", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-6a239526fac34bcc9894cfee622ca3a4", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-7529fd6dd7004bc6842a048dbe5f25cc", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-11e24a6aacb34945ba8db8b0a1f76088", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-b1ac676f141f4700bf7a6461416bf409", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-cf3b107ef2f143bf9071cd2d97d83a02", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-86063bc2e4f9408c90a68336b7d0b233", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-38ec094e925c4284a95356064aa65287", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-015937d27ef34a46b5ef9f61bde201e1", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-476afc7e273347f9bd276d7b148cf931", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-1d70b9eb3b884de6b1e5b8b30a25f2b4", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-66904ffb7b03468eaac045c49a84d854", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-9399618c5b70447fa35668bbe36d2da8", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-cb4872e5db3e4e259d3f87e69917426c", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-14099290be73415196ac10c7668e7aaf", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-bc7ff3f59cfd44729a2396f96ae5506c", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-5a4d869e768940439c9c3f0672b4f188", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-106a2c55943a4191b61ee447cf14797b", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-04de312db7184d038e58eb517b6b4977", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-c3c6ea1a42034a1abe5bbb20adff156d", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-ac2a4675e933469195468c03c2062381", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-4b7ce801ab4b4c89baa38f79b25c873b", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-eb10661e86af495b8acef4aac7e1af86", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-2d11d0b5706c470bb25b9eb3ec8ab140", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-5916246072a346c986fd14202099c13e", "keywords": [], "children": [], "keywords_must": [], @@ -3008,7 +3773,259 @@ }, { "exercises": { - "node_id": "dailycode-5d88f5aea60b4d6e9dbd83c13e22993f", + "node_id": "dailycode-51ab560c60e241f9ba4b1f449db8f4fc", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-a6beddb2efc64ddc8a28e593dfefc807", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-1b393b30506f43f6874f85036d16a3de", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-6c74549bf696457084ef66af3c8ab6e0", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-9480f3a882734848aeea80c4b8e0fa7c", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-73f719eb3c124f11933e47c2cbcf4c7c", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-d1ede2d2c5a54e91a19273b3f31978c5", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-3880837d907340c9a9e96939e9fbae92", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-ba756fd53d6f45139d2d818d4a555fb7", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-09529ae417314d8cb84c07be9aec2849", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-a6c3e70f1c0045c1b2929f56cc5ce02f", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-eef49c9c9f0943f2a27bb9f4dfb22718", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-81f91206205e431f9ce2fa179955ecfa", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-b2dbc54134bf4e8a961f1b155e8c665b", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-58550dadc0174b719c8769c5d87c8814", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-74b60540beef43f7b8e98cf2d1a4580c", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-248163efec6747ce852e85ea2dbe3c15", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-f16026ed484a444fb95e3d6698f5f119", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-841814f7ce5d4aa18c3caecf27c8c494", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-70f141b3ad9d46febf18fbdbaf90c0f4", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-2d3f4293f7a84ff2a372da173fcdd96e", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-042b2c59e8c44737861a74454b50c22a", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-c32c095cff5545278e9e9e51bb3cdbe1", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-d5fa1747371e4789932aeed9ee27bcdb", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-b3f62c12a2624288bb79b4210b44e046", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-afe07aa3dd7c45bc9d6ceb91b6349f93", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-c93700cb5c094f74a66dfef7fa2ab6b3", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-5566db3ee0444562987747d551bcd75f", + "keywords": [], + "children": [], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "exercises": { + "node_id": "dailycode-afaa892994bc4a7c920701ff7efc3384", "keywords": [], "children": [], "keywords_must": [], @@ -3017,7 +4034,7 @@ }, { "exercises": { - "node_id": "dailycode-04711f16d9ef4c92a4b8c611f05fa4d4", + "node_id": "dailycode-93f92073f6254a549ac8e0010c008337", "keywords": [], "children": [], "keywords_must": [], @@ -3026,7 +4043,7 @@ }, { "exercises": { - "node_id": "dailycode-7f4aaca343fc40549296badcaa53bf03", + "node_id": "dailycode-c35251e8f87a49a7a4b5e149f073dea8", "keywords": [], "children": [], "keywords_must": [], @@ -3035,7 +4052,7 @@ }, { "exercises": { - "node_id": "dailycode-5b037f31a3c849158d21cbaed4173fa7", + "node_id": "dailycode-826dfcaf541147bb8be5b8a3103697ad", "keywords": [], "children": [], "keywords_must": [], @@ -3044,7 +4061,7 @@ }, { "exercises": { - "node_id": "dailycode-ac4ab7abcdeb482bb23684e08a27e9ed", + "node_id": "dailycode-4636efcd81dd4e2a9f8f83ab23b80ffe", "keywords": [], "children": [], "keywords_must": [], @@ -3053,7 +4070,7 @@ }, { "exercises": { - "node_id": "dailycode-df624f99477f4489b3508b5d947545e6", + "node_id": "dailycode-1964e4bf97984234a14f997bb1352fcb", "keywords": [], "children": [], "keywords_must": [], @@ -3062,7 +4079,7 @@ }, { "exercises": { - "node_id": "dailycode-a91ab2d4ae12479088f6fe0653c5f877", + "node_id": "dailycode-74b08309f19b41869c4320ea58482f6c", "keywords": [], "children": [], "keywords_must": [], @@ -3071,7 +4088,7 @@ }, { "exercises": { - "node_id": "dailycode-dab42155788f4df992f7bee3d2ceaff3", + "node_id": "dailycode-60c41833285047f3b321443845611bce", "keywords": [], "children": [], "keywords_must": [], @@ -3080,7 +4097,7 @@ }, { "exercises": { - "node_id": "dailycode-b930e3c023e1440ebb20130a7a2d188b", + "node_id": "dailycode-dff4c4e10e6f42a1ac201dd4d0ff8664", "keywords": [], "children": [], "keywords_must": [], @@ -3089,7 +4106,7 @@ }, { "exercises": { - "node_id": "dailycode-0cef0ea9a9464eb8acb4a439fde7c351", + "node_id": "dailycode-b8f6aa5c87444972987d7e7a1e52a22c", "keywords": [], "children": [], "keywords_must": [], @@ -3098,7 +4115,7 @@ }, { "exercises": { - "node_id": "dailycode-707a9a26d46749e9a9e2dde825d0421c", + "node_id": "dailycode-d26621ba92b24aeeb003c86d47d36ad6", "keywords": [], "children": [], "keywords_must": [], @@ -3107,7 +4124,7 @@ }, { "exercises": { - "node_id": "dailycode-f5bede05c3a2454090a4bccc0479462f", + "node_id": "dailycode-935af29ed8e5492cbb0712c8b1d0c653", "keywords": [], "children": [], "keywords_must": [], @@ -3116,7 +4133,7 @@ }, { "exercises": { - "node_id": "dailycode-390b583c367d440f80eaa10524618444", + "node_id": "dailycode-d202c192ccde42a8a79bb7439fc7bf10", "keywords": [], "children": [], "keywords_must": [], @@ -3125,7 +4142,7 @@ }, { "exercises": { - "node_id": "dailycode-2d92b024f38245afa28cec2ec78b78cf", + "node_id": "dailycode-2728da0a5a584b3b8eee17473182c2e2", "keywords": [], "children": [], "keywords_must": [], @@ -3134,7 +4151,7 @@ }, { "exercises": { - "node_id": "dailycode-d42952ba501a46e5a121004d2f62e724", + "node_id": "dailycode-4e7bac103be94ad1b0b11a1ee6256987", "keywords": [], "children": [], "keywords_must": [], @@ -3143,7 +4160,7 @@ }, { "exercises": { - "node_id": "dailycode-0c1bff5243bc4c4fbb688b0c8e1d1bc0", + "node_id": "dailycode-acbff7e537ff4e00aafefb58ac6f1bd8", "keywords": [], "children": [], "keywords_must": [], @@ -3152,7 +4169,7 @@ }, { "exercises": { - "node_id": "dailycode-33f647ff549d4301a57cd82b9872bbf8", + "node_id": "dailycode-b84e0ad3b5c8484ab8dbb922eeead085", "keywords": [], "children": [], "keywords_must": [], @@ -3161,7 +4178,7 @@ }, { "exercises": { - "node_id": "dailycode-7077b339c1ef498ca92107cbc966a652", + "node_id": "dailycode-abe1e612615b4a0cb30c4d43d8317bcf", "keywords": [], "children": [], "keywords_must": [], @@ -3170,7 +4187,7 @@ }, { "exercises": { - "node_id": "dailycode-8159c79d4b6e4544bf44d1f7b9a57ff9", + "node_id": "dailycode-9c576c7dcc0247e2ae923077462c4baa", "keywords": [], "children": [], "keywords_must": [], @@ -3179,7 +4196,7 @@ }, { "exercises": { - "node_id": "dailycode-d44bd3f0766b4d3b92ff5b5ded112675", + "node_id": "dailycode-0c3ef2e1bd1242338188dd04275436e9", "keywords": [], "children": [], "keywords_must": [], @@ -3188,7 +4205,7 @@ }, { "exercises": { - "node_id": "dailycode-69ef472d89dd4a86ba769fd50d0ad909", + "node_id": "dailycode-6595ec837a47451bb033b3d82cbcf542", "keywords": [], "children": [], "keywords_must": [], @@ -3197,7 +4214,7 @@ }, { "exercises": { - "node_id": "dailycode-022a4daf03b444b1b4fed08a83b469cd", + "node_id": "dailycode-2e0242542523489684fe462e57e5dc2d", "keywords": [], "children": [], "keywords_must": [], @@ -3206,7 +4223,7 @@ }, { "exercises": { - "node_id": "dailycode-22d0c66ac13e492ab38799ba4281480b", + "node_id": "dailycode-75dace4205f44a3598936beb6e9bab7a", "keywords": [], "children": [], "keywords_must": [], @@ -3215,7 +4232,7 @@ }, { "exercises": { - "node_id": "dailycode-6a239526fac34bcc9894cfee622ca3a4", + "node_id": "dailycode-0de614ddd4a841aca80d2037ae64bfe9", "keywords": [], "children": [], "keywords_must": [], @@ -3224,7 +4241,7 @@ }, { "exercises": { - "node_id": "dailycode-7529fd6dd7004bc6842a048dbe5f25cc", + "node_id": "dailycode-ee972a8c3ad94ef4937a12be5da23849", "keywords": [], "children": [], "keywords_must": [], @@ -3233,7 +4250,7 @@ }, { "exercises": { - "node_id": "dailycode-11e24a6aacb34945ba8db8b0a1f76088", + "node_id": "dailycode-7ab771c2a0454a8d88061ebc100eb41e", "keywords": [], "children": [], "keywords_must": [], @@ -3242,7 +4259,7 @@ }, { "exercises": { - "node_id": "dailycode-b1ac676f141f4700bf7a6461416bf409", + "node_id": "dailycode-c86e8718d6a14cbcb86586cfeded8a86", "keywords": [], "children": [], "keywords_must": [], @@ -3251,7 +4268,7 @@ }, { "exercises": { - "node_id": "dailycode-cf3b107ef2f143bf9071cd2d97d83a02", + "node_id": "dailycode-0f4fa52ce6504716996db85e4c9e493a", "keywords": [], "children": [], "keywords_must": [], @@ -3260,7 +4277,7 @@ }, { "exercises": { - "node_id": "dailycode-86063bc2e4f9408c90a68336b7d0b233", + "node_id": "dailycode-a60d5b2274744417bc065e034719adb5", "keywords": [], "children": [], "keywords_must": [], @@ -3269,7 +4286,7 @@ }, { "exercises": { - "node_id": "dailycode-38ec094e925c4284a95356064aa65287", + "node_id": "dailycode-36ed7137f34d4fd2b2b5e101ce9756bb", "keywords": [], "children": [], "keywords_must": [], @@ -3278,7 +4295,7 @@ }, { "exercises": { - "node_id": "dailycode-015937d27ef34a46b5ef9f61bde201e1", + "node_id": "dailycode-0eb990da86e340998c215d3a1d8aa859", "keywords": [], "children": [], "keywords_must": [], @@ -3287,7 +4304,7 @@ }, { "exercises": { - "node_id": "dailycode-476afc7e273347f9bd276d7b148cf931", + "node_id": "dailycode-f69b5024f7ea4a72811393706d30e524", "keywords": [], "children": [], "keywords_must": [], @@ -3296,7 +4313,7 @@ }, { "exercises": { - "node_id": "dailycode-1d70b9eb3b884de6b1e5b8b30a25f2b4", + "node_id": "dailycode-05046db437fa4f03bd4e5f082a388673", "keywords": [], "children": [], "keywords_must": [], @@ -3305,7 +4322,7 @@ }, { "exercises": { - "node_id": "dailycode-66904ffb7b03468eaac045c49a84d854", + "node_id": "dailycode-e33c5f27e8214636a42bc8cf443ac7dc", "keywords": [], "children": [], "keywords_must": [], @@ -3314,7 +4331,7 @@ }, { "exercises": { - "node_id": "dailycode-9399618c5b70447fa35668bbe36d2da8", + "node_id": "dailycode-d7d3abfcdce548ab912b7845ab999a96", "keywords": [], "children": [], "keywords_must": [], @@ -3323,7 +4340,7 @@ }, { "exercises": { - "node_id": "dailycode-cb4872e5db3e4e259d3f87e69917426c", + "node_id": "dailycode-dd9ab1f390244fc09b52747485de90a5", "keywords": [], "children": [], "keywords_must": [], @@ -3332,7 +4349,7 @@ }, { "exercises": { - "node_id": "dailycode-14099290be73415196ac10c7668e7aaf", + "node_id": "dailycode-5e49fb70f7ba4fa581a2b1e1aa9afeca", "keywords": [], "children": [], "keywords_must": [], @@ -3341,7 +4358,7 @@ }, { "exercises": { - "node_id": "dailycode-bc7ff3f59cfd44729a2396f96ae5506c", + "node_id": "dailycode-fac5c17f457d4cf4b5cf2636c80ffa31", "keywords": [], "children": [], "keywords_must": [], @@ -3350,7 +4367,7 @@ }, { "exercises": { - "node_id": "dailycode-5a4d869e768940439c9c3f0672b4f188", + "node_id": "dailycode-4a38b31d688641b9843b28b4f373d6e2", "keywords": [], "children": [], "keywords_must": [], @@ -3359,7 +4376,7 @@ }, { "exercises": { - "node_id": "dailycode-106a2c55943a4191b61ee447cf14797b", + "node_id": "dailycode-734b902304404565abebe151f9f77153", "keywords": [], "children": [], "keywords_must": [], @@ -3368,7 +4385,7 @@ }, { "exercises": { - "node_id": "dailycode-04de312db7184d038e58eb517b6b4977", + "node_id": "dailycode-6bfbac883a8f424d89c5d4bd00c1166a", "keywords": [], "children": [], "keywords_must": [], @@ -3377,7 +4394,7 @@ }, { "exercises": { - "node_id": "dailycode-c3c6ea1a42034a1abe5bbb20adff156d", + "node_id": "dailycode-617ecf41c10541368e4d2585d3a5f77c", "keywords": [], "children": [], "keywords_must": [], @@ -3386,7 +4403,7 @@ }, { "exercises": { - "node_id": "dailycode-ac2a4675e933469195468c03c2062381", + "node_id": "dailycode-a4304e9fcd084439be358b1e58347100", "keywords": [], "children": [], "keywords_must": [], @@ -3395,7 +4412,7 @@ }, { "exercises": { - "node_id": "dailycode-4b7ce801ab4b4c89baa38f79b25c873b", + "node_id": "dailycode-96ae9dfe598347d1ab79aa2750046db6", "keywords": [], "children": [], "keywords_must": [], @@ -3404,16 +4421,26 @@ }, { "exercises": { - "node_id": "dailycode-eb10661e86af495b8acef4aac7e1af86", + "node_id": "dailycode-b42a7f99c1f84575bed9b796d6c8bf85", "keywords": [], "children": [], "keywords_must": [], "keywords_forbid": [] } - }, + } + ], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "java": { + "node_id": "dailycode-5aeca2a930d442919a9fb9c5d2362e95", + "keywords": [], + "children": [ { "exercises": { - "node_id": "dailycode-2d11d0b5706c470bb25b9eb3ec8ab140", + "node_id": "dailycode-e4f08941ea62439cb49087bb21e1fdb1", "keywords": [], "children": [], "keywords_must": [], @@ -3422,7 +4449,7 @@ }, { "exercises": { - "node_id": "dailycode-5916246072a346c986fd14202099c13e", + "node_id": "dailycode-2c34fdc356ec41e1ae1c01be149ec729", "keywords": [], "children": [], "keywords_must": [], @@ -3431,7 +4458,7 @@ }, { "exercises": { - "node_id": "dailycode-51ab560c60e241f9ba4b1f449db8f4fc", + "node_id": "dailycode-bc6b2d6511254a5f98339f5f75c558a6", "keywords": [], "children": [], "keywords_must": [], @@ -3440,7 +4467,7 @@ }, { "exercises": { - "node_id": "dailycode-a6beddb2efc64ddc8a28e593dfefc807", + "node_id": "dailycode-5bd0909b7195425cb8eb7497477bdc33", "keywords": [], "children": [], "keywords_must": [], @@ -3449,7 +4476,7 @@ }, { "exercises": { - "node_id": "dailycode-1b393b30506f43f6874f85036d16a3de", + "node_id": "dailycode-adbef0040dc440618bed1f48bef2c16c", "keywords": [], "children": [], "keywords_must": [], @@ -3458,7 +4485,7 @@ }, { "exercises": { - "node_id": "dailycode-6c74549bf696457084ef66af3c8ab6e0", + "node_id": "dailycode-77a803dcb98440b7a136a24276b6854d", "keywords": [], "children": [], "keywords_must": [], @@ -3467,7 +4494,7 @@ }, { "exercises": { - "node_id": "dailycode-9480f3a882734848aeea80c4b8e0fa7c", + "node_id": "dailycode-9d0fc0cf99704e4684d62717fcf0025e", "keywords": [], "children": [], "keywords_must": [], @@ -3476,7 +4503,7 @@ }, { "exercises": { - "node_id": "dailycode-73f719eb3c124f11933e47c2cbcf4c7c", + "node_id": "dailycode-21945d925ace44438887c1e03e5fa8ca", "keywords": [], "children": [], "keywords_must": [], @@ -3485,7 +4512,7 @@ }, { "exercises": { - "node_id": "dailycode-d1ede2d2c5a54e91a19273b3f31978c5", + "node_id": "dailycode-cdfa1a7c19ef4e879fcab664e5c47371", "keywords": [], "children": [], "keywords_must": [], @@ -3494,7 +4521,7 @@ }, { "exercises": { - "node_id": "dailycode-3880837d907340c9a9e96939e9fbae92", + "node_id": "dailycode-b97a45db1664450db39afacc504f65c7", "keywords": [], "children": [], "keywords_must": [], @@ -3503,7 +4530,7 @@ }, { "exercises": { - "node_id": "dailycode-ba756fd53d6f45139d2d818d4a555fb7", + "node_id": "dailycode-cba3b9fdcdbc447981e98ac7d67b82c6", "keywords": [], "children": [], "keywords_must": [], @@ -3512,7 +4539,7 @@ }, { "exercises": { - "node_id": "dailycode-09529ae417314d8cb84c07be9aec2849", + "node_id": "dailycode-2b9e60620fe645f883040218b22a8d76", "keywords": [], "children": [], "keywords_must": [], @@ -3521,7 +4548,7 @@ }, { "exercises": { - "node_id": "dailycode-a6c3e70f1c0045c1b2929f56cc5ce02f", + "node_id": "dailycode-150f426952d9492f81925cff61127646", "keywords": [], "children": [], "keywords_must": [], @@ -3530,7 +4557,7 @@ }, { "exercises": { - "node_id": "dailycode-eef49c9c9f0943f2a27bb9f4dfb22718", + "node_id": "dailycode-e7dd2c02e6b94b02a2cba6cb32b0c0dc", "keywords": [], "children": [], "keywords_must": [], @@ -3539,7 +4566,7 @@ }, { "exercises": { - "node_id": "dailycode-81f91206205e431f9ce2fa179955ecfa", + "node_id": "dailycode-a176e82f286443f5a97e226011b84a70", "keywords": [], "children": [], "keywords_must": [], @@ -3548,7 +4575,7 @@ }, { "exercises": { - "node_id": "dailycode-b2dbc54134bf4e8a961f1b155e8c665b", + "node_id": "dailycode-c49e020840b741d485bc11bf0855b4e8", "keywords": [], "children": [], "keywords_must": [], @@ -3557,7 +4584,7 @@ }, { "exercises": { - "node_id": "dailycode-58550dadc0174b719c8769c5d87c8814", + "node_id": "dailycode-5d5d68a0fee64164be313bddd528142f", "keywords": [], "children": [], "keywords_must": [], @@ -3566,7 +4593,7 @@ }, { "exercises": { - "node_id": "dailycode-74b60540beef43f7b8e98cf2d1a4580c", + "node_id": "dailycode-2b4e10e9e01a4775a03f2a7bd8cac54c", "keywords": [], "children": [], "keywords_must": [], @@ -3575,7 +4602,7 @@ }, { "exercises": { - "node_id": "dailycode-248163efec6747ce852e85ea2dbe3c15", + "node_id": "dailycode-0fc1b6a999914e309d0a0e484e5e0c85", "keywords": [], "children": [], "keywords_must": [], @@ -3584,7 +4611,7 @@ }, { "exercises": { - "node_id": "dailycode-f16026ed484a444fb95e3d6698f5f119", + "node_id": "dailycode-b087bfd39b6949ab8e67326033d74792", "keywords": [], "children": [], "keywords_must": [], @@ -3593,7 +4620,7 @@ }, { "exercises": { - "node_id": "dailycode-841814f7ce5d4aa18c3caecf27c8c494", + "node_id": "dailycode-512d40c59a874474a237294910486e0a", "keywords": [], "children": [], "keywords_must": [], @@ -3602,7 +4629,7 @@ }, { "exercises": { - "node_id": "dailycode-70f141b3ad9d46febf18fbdbaf90c0f4", + "node_id": "dailycode-7fa5cb6f690545fc865aece3cd1a74a9", "keywords": [], "children": [], "keywords_must": [], @@ -3611,7 +4638,7 @@ }, { "exercises": { - "node_id": "dailycode-2d3f4293f7a84ff2a372da173fcdd96e", + "node_id": "dailycode-06979d4bde9b4d048a028977d9bee368", "keywords": [], "children": [], "keywords_must": [], @@ -3620,7 +4647,7 @@ }, { "exercises": { - "node_id": "dailycode-042b2c59e8c44737861a74454b50c22a", + "node_id": "dailycode-6defda4fbc254df7a3a4f2f78233091a", "keywords": [], "children": [], "keywords_must": [], @@ -3629,7 +4656,7 @@ }, { "exercises": { - "node_id": "dailycode-c32c095cff5545278e9e9e51bb3cdbe1", + "node_id": "dailycode-f7794a1f875c4fbdb5c90aa69bbb1d1c", "keywords": [], "children": [], "keywords_must": [], @@ -3638,7 +4665,7 @@ }, { "exercises": { - "node_id": "dailycode-d5fa1747371e4789932aeed9ee27bcdb", + "node_id": "dailycode-8df6b07a74a3448ab4d1ed17cd59ece4", "keywords": [], "children": [], "keywords_must": [], @@ -3647,7 +4674,7 @@ }, { "exercises": { - "node_id": "dailycode-b3f62c12a2624288bb79b4210b44e046", + "node_id": "dailycode-63f1dfb5737e4d0eb3afba4a75fecd8e", "keywords": [], "children": [], "keywords_must": [], @@ -3656,7 +4683,7 @@ }, { "exercises": { - "node_id": "dailycode-afe07aa3dd7c45bc9d6ceb91b6349f93", + "node_id": "dailycode-290dbf6b65274179954a9f182f7a2f98", "keywords": [], "children": [], "keywords_must": [], @@ -3665,7 +4692,7 @@ }, { "exercises": { - "node_id": "dailycode-c93700cb5c094f74a66dfef7fa2ab6b3", + "node_id": "dailycode-423001ac26c44d20a3572064866b8a29", "keywords": [], "children": [], "keywords_must": [], @@ -3674,7 +4701,7 @@ }, { "exercises": { - "node_id": "dailycode-5566db3ee0444562987747d551bcd75f", + "node_id": "dailycode-ce734aa4eff1425fab72592000d1eaba", "keywords": [], "children": [], "keywords_must": [], @@ -3683,7 +4710,7 @@ }, { "exercises": { - "node_id": "dailycode-afaa892994bc4a7c920701ff7efc3384", + "node_id": "dailycode-f73b6a74269147239eb2e60bb9b1bec0", "keywords": [], "children": [], "keywords_must": [], @@ -3692,7 +4719,7 @@ }, { "exercises": { - "node_id": "dailycode-93f92073f6254a549ac8e0010c008337", + "node_id": "dailycode-38686faac5e447d8b52391e777bd15b5", "keywords": [], "children": [], "keywords_must": [], @@ -3701,7 +4728,7 @@ }, { "exercises": { - "node_id": "dailycode-c35251e8f87a49a7a4b5e149f073dea8", + "node_id": "dailycode-b797b4502b324dbcb41cc7d3ddb2bdbd", "keywords": [], "children": [], "keywords_must": [], @@ -3710,7 +4737,7 @@ }, { "exercises": { - "node_id": "dailycode-826dfcaf541147bb8be5b8a3103697ad", + "node_id": "dailycode-4a27c74c6807494493bee7bc2b275d32", "keywords": [], "children": [], "keywords_must": [], @@ -3719,7 +4746,7 @@ }, { "exercises": { - "node_id": "dailycode-4636efcd81dd4e2a9f8f83ab23b80ffe", + "node_id": "dailycode-596c3dac8f6c4d31a61477304a726299", "keywords": [], "children": [], "keywords_must": [], @@ -3728,26 +4755,16 @@ }, { "exercises": { - "node_id": "dailycode-1964e4bf97984234a14f997bb1352fcb", + "node_id": "dailycode-50818484f6ab4ab08262ca694785cdbb", "keywords": [], "children": [], "keywords_must": [], "keywords_forbid": [] } - } - ], - "keywords_must": [], - "keywords_forbid": [] - } - }, - { - "java": { - "node_id": "dailycode-5aeca2a930d442919a9fb9c5d2362e95", - "keywords": [], - "children": [ + }, { "exercises": { - "node_id": "dailycode-e4f08941ea62439cb49087bb21e1fdb1", + "node_id": "dailycode-aa14a10d3dbc4e2a983c7cffd4eca240", "keywords": [], "children": [], "keywords_must": [], @@ -3756,7 +4773,7 @@ }, { "exercises": { - "node_id": "dailycode-2c34fdc356ec41e1ae1c01be149ec729", + "node_id": "dailycode-e782222cd8894664b3febf53492cbc11", "keywords": [], "children": [], "keywords_must": [], @@ -3765,7 +4782,7 @@ }, { "exercises": { - "node_id": "dailycode-bc6b2d6511254a5f98339f5f75c558a6", + "node_id": "dailycode-68a4069880464d59a2b217ebc248c3b7", "keywords": [], "children": [], "keywords_must": [], @@ -3774,7 +4791,7 @@ }, { "exercises": { - "node_id": "dailycode-5bd0909b7195425cb8eb7497477bdc33", + "node_id": "dailycode-c4d4538cdb4544b1871d8b2c95d3893b", "keywords": [], "children": [], "keywords_must": [], @@ -3783,7 +4800,7 @@ }, { "exercises": { - "node_id": "dailycode-adbef0040dc440618bed1f48bef2c16c", + "node_id": "dailycode-7873feae482441e5abe2a0319821f44c", "keywords": [], "children": [], "keywords_must": [], @@ -3792,7 +4809,7 @@ }, { "exercises": { - "node_id": "dailycode-77a803dcb98440b7a136a24276b6854d", + "node_id": "dailycode-e9998c9054be454eb2a0a4f69e129830", "keywords": [], "children": [], "keywords_must": [], @@ -3801,7 +4818,7 @@ }, { "exercises": { - "node_id": "dailycode-9d0fc0cf99704e4684d62717fcf0025e", + "node_id": "dailycode-40c4c366546a44b5930491db827d2c14", "keywords": [], "children": [], "keywords_must": [], @@ -3810,7 +4827,7 @@ }, { "exercises": { - "node_id": "dailycode-21945d925ace44438887c1e03e5fa8ca", + "node_id": "dailycode-ccc2cd1afb9b4c05abec6e80d581bfd2", "keywords": [], "children": [], "keywords_must": [], @@ -3819,7 +4836,7 @@ }, { "exercises": { - "node_id": "dailycode-cdfa1a7c19ef4e879fcab664e5c47371", + "node_id": "dailycode-47ce044c35bd436a8c83976d0f209db9", "keywords": [], "children": [], "keywords_must": [], @@ -3828,7 +4845,7 @@ }, { "exercises": { - "node_id": "dailycode-b97a45db1664450db39afacc504f65c7", + "node_id": "dailycode-68cfc35ac6174d01bfb5751c70035252", "keywords": [], "children": [], "keywords_must": [], @@ -3837,7 +4854,7 @@ }, { "exercises": { - "node_id": "dailycode-cba3b9fdcdbc447981e98ac7d67b82c6", + "node_id": "dailycode-97b59f64908e447ca8f6cc62c7d69b2a", "keywords": [], "children": [], "keywords_must": [], @@ -3846,7 +4863,7 @@ }, { "exercises": { - "node_id": "dailycode-2b9e60620fe645f883040218b22a8d76", + "node_id": "dailycode-0da11b12c20540a69a7df7f71bc052af", "keywords": [], "children": [], "keywords_must": [], @@ -3855,7 +4872,7 @@ }, { "exercises": { - "node_id": "dailycode-150f426952d9492f81925cff61127646", + "node_id": "dailycode-a4f351932be94d9388ffb510d2ff8dc4", "keywords": [], "children": [], "keywords_must": [], @@ -3864,7 +4881,7 @@ }, { "exercises": { - "node_id": "dailycode-e7dd2c02e6b94b02a2cba6cb32b0c0dc", + "node_id": "dailycode-620f5bfe852e4cbd9ce5c2eb848eba27", "keywords": [], "children": [], "keywords_must": [], @@ -3873,7 +4890,7 @@ }, { "exercises": { - "node_id": "dailycode-a176e82f286443f5a97e226011b84a70", + "node_id": "dailycode-7c1a5ad714c441d7a0ccdee3c819e4c6", "keywords": [], "children": [], "keywords_must": [], @@ -3882,7 +4899,7 @@ }, { "exercises": { - "node_id": "dailycode-c49e020840b741d485bc11bf0855b4e8", + "node_id": "dailycode-a51891de4bbd4992a1ca2d8d786bbc10", "keywords": [], "children": [], "keywords_must": [], @@ -3891,7 +4908,7 @@ }, { "exercises": { - "node_id": "dailycode-5d5d68a0fee64164be313bddd528142f", + "node_id": "dailycode-c1da5b7b32894b2691bf58b40188b67c", "keywords": [], "children": [], "keywords_must": [], @@ -3900,7 +4917,7 @@ }, { "exercises": { - "node_id": "dailycode-2b4e10e9e01a4775a03f2a7bd8cac54c", + "node_id": "dailycode-6a33231763734cb28a58cca9e68d7ecd", "keywords": [], "children": [], "keywords_must": [], @@ -3909,7 +4926,7 @@ }, { "exercises": { - "node_id": "dailycode-0fc1b6a999914e309d0a0e484e5e0c85", + "node_id": "dailycode-d433cef163fe4e2fbdf5bef441506da8", "keywords": [], "children": [], "keywords_must": [], @@ -3918,7 +4935,7 @@ }, { "exercises": { - "node_id": "dailycode-b087bfd39b6949ab8e67326033d74792", + "node_id": "dailycode-7422725251434d6f802d5c3c67d3d8b2", "keywords": [], "children": [], "keywords_must": [], @@ -3927,7 +4944,7 @@ }, { "exercises": { - "node_id": "dailycode-512d40c59a874474a237294910486e0a", + "node_id": "dailycode-6007336fac224f659d45e9b3829c6726", "keywords": [], "children": [], "keywords_must": [], @@ -3936,7 +4953,7 @@ }, { "exercises": { - "node_id": "dailycode-7fa5cb6f690545fc865aece3cd1a74a9", + "node_id": "dailycode-bcd5c08f84344295bc2f185d6944f7c2", "keywords": [], "children": [], "keywords_must": [], @@ -3945,7 +4962,7 @@ }, { "exercises": { - "node_id": "dailycode-06979d4bde9b4d048a028977d9bee368", + "node_id": "dailycode-16ecbc0a44ff4036aaf4be01fd07e40f", "keywords": [], "children": [], "keywords_must": [], @@ -3954,7 +4971,7 @@ }, { "exercises": { - "node_id": "dailycode-6defda4fbc254df7a3a4f2f78233091a", + "node_id": "dailycode-b6ed4d3d6d31409fb7f1fcc072ce4295", "keywords": [], "children": [], "keywords_must": [], @@ -3963,7 +4980,7 @@ }, { "exercises": { - "node_id": "dailycode-f7794a1f875c4fbdb5c90aa69bbb1d1c", + "node_id": "dailycode-06dec96ef4e941b5b10c3a4feae74ddb", "keywords": [], "children": [], "keywords_must": [], @@ -3972,7 +4989,7 @@ }, { "exercises": { - "node_id": "dailycode-8df6b07a74a3448ab4d1ed17cd59ece4", + "node_id": "dailycode-ed11e080bba44d2bb7ec98bbddac3ffc", "keywords": [], "children": [], "keywords_must": [], @@ -3981,7 +4998,7 @@ }, { "exercises": { - "node_id": "dailycode-63f1dfb5737e4d0eb3afba4a75fecd8e", + "node_id": "dailycode-da11ba53a9bb4e6b8880a2cd184933d4", "keywords": [], "children": [], "keywords_must": [], @@ -3990,16 +5007,26 @@ }, { "exercises": { - "node_id": "dailycode-290dbf6b65274179954a9f182f7a2f98", + "node_id": "dailycode-56e99b722b5641bc884da20f47a9386f", "keywords": [], "children": [], "keywords_must": [], "keywords_forbid": [] } - }, + } + ], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "python": { + "node_id": "dailycode-6adb56f72172439c9d712de16b8d504c", + "keywords": [], + "children": [ { "exercises": { - "node_id": "dailycode-423001ac26c44d20a3572064866b8a29", + "node_id": "dailycode-c4bd91e863e346e8860401ab6914732e", "keywords": [], "children": [], "keywords_must": [], @@ -4008,7 +5035,7 @@ }, { "exercises": { - "node_id": "dailycode-ce734aa4eff1425fab72592000d1eaba", + "node_id": "dailycode-10743c3216c44bb1a4acda922204abf7", "keywords": [], "children": [], "keywords_must": [], @@ -4017,7 +5044,7 @@ }, { "exercises": { - "node_id": "dailycode-f73b6a74269147239eb2e60bb9b1bec0", + "node_id": "dailycode-df5089b6b16346dcb5d24198a0eb1e37", "keywords": [], "children": [], "keywords_must": [], @@ -4026,7 +5053,7 @@ }, { "exercises": { - "node_id": "dailycode-38686faac5e447d8b52391e777bd15b5", + "node_id": "dailycode-e255b434da964a3e8c1104d1242677a5", "keywords": [], "children": [], "keywords_must": [], @@ -4035,7 +5062,7 @@ }, { "exercises": { - "node_id": "dailycode-b797b4502b324dbcb41cc7d3ddb2bdbd", + "node_id": "dailycode-d23d7c0418f84280a2ef890bb4fb1757", "keywords": [], "children": [], "keywords_must": [], @@ -4044,7 +5071,7 @@ }, { "exercises": { - "node_id": "dailycode-4a27c74c6807494493bee7bc2b275d32", + "node_id": "dailycode-a7329b367a72496381d22bcbc15b0ab1", "keywords": [], "children": [], "keywords_must": [], @@ -4053,7 +5080,7 @@ }, { "exercises": { - "node_id": "dailycode-596c3dac8f6c4d31a61477304a726299", + "node_id": "dailycode-b1f1ffa8aa944017bc6c7f4d7b9cece2", "keywords": [], "children": [], "keywords_must": [], @@ -4062,7 +5089,7 @@ }, { "exercises": { - "node_id": "dailycode-50818484f6ab4ab08262ca694785cdbb", + "node_id": "dailycode-62b760478e454f309a425bf1da91ecd9", "keywords": [], "children": [], "keywords_must": [], @@ -4071,7 +5098,7 @@ }, { "exercises": { - "node_id": "dailycode-aa14a10d3dbc4e2a983c7cffd4eca240", + "node_id": "dailycode-527f1c40eca54c19be59eb9d93305dc3", "keywords": [], "children": [], "keywords_must": [], @@ -4080,7 +5107,7 @@ }, { "exercises": { - "node_id": "dailycode-e782222cd8894664b3febf53492cbc11", + "node_id": "dailycode-69fd78974192450ebe5d6fe0bbdbfa67", "keywords": [], "children": [], "keywords_must": [], @@ -4089,7 +5116,7 @@ }, { "exercises": { - "node_id": "dailycode-68a4069880464d59a2b217ebc248c3b7", + "node_id": "dailycode-061ac0473af848a6aea1b1d7380686f7", "keywords": [], "children": [], "keywords_must": [], @@ -4098,7 +5125,7 @@ }, { "exercises": { - "node_id": "dailycode-c4d4538cdb4544b1871d8b2c95d3893b", + "node_id": "dailycode-ebc866b086ae44a79c65cb99235a170a", "keywords": [], "children": [], "keywords_must": [], @@ -4107,7 +5134,7 @@ }, { "exercises": { - "node_id": "dailycode-7873feae482441e5abe2a0319821f44c", + "node_id": "dailycode-0da6d95ed1b54b8e83d0193c88e6c237", "keywords": [], "children": [], "keywords_must": [], @@ -4116,7 +5143,7 @@ }, { "exercises": { - "node_id": "dailycode-e9998c9054be454eb2a0a4f69e129830", + "node_id": "dailycode-89a4d210cf6b4a96ab49088e293fdd9f", "keywords": [], "children": [], "keywords_must": [], @@ -4125,7 +5152,7 @@ }, { "exercises": { - "node_id": "dailycode-40c4c366546a44b5930491db827d2c14", + "node_id": "dailycode-74272d3291224f24af9d13e734d733f5", "keywords": [], "children": [], "keywords_must": [], @@ -4134,7 +5161,7 @@ }, { "exercises": { - "node_id": "dailycode-ccc2cd1afb9b4c05abec6e80d581bfd2", + "node_id": "dailycode-1cb29400682c421faa8d5b7cb588faef", "keywords": [], "children": [], "keywords_must": [], @@ -4143,7 +5170,7 @@ }, { "exercises": { - "node_id": "dailycode-47ce044c35bd436a8c83976d0f209db9", + "node_id": "dailycode-fe3d45a08a0f47858df48e044d0ae2f9", "keywords": [], "children": [], "keywords_must": [], @@ -4152,7 +5179,7 @@ }, { "exercises": { - "node_id": "dailycode-68cfc35ac6174d01bfb5751c70035252", + "node_id": "dailycode-8c22cff947234df7a45ae4e553106499", "keywords": [], "children": [], "keywords_must": [], @@ -4161,7 +5188,7 @@ }, { "exercises": { - "node_id": "dailycode-97b59f64908e447ca8f6cc62c7d69b2a", + "node_id": "dailycode-3e9f6ff35d514b77a9785d61386e9093", "keywords": [], "children": [], "keywords_must": [], @@ -4170,7 +5197,7 @@ }, { "exercises": { - "node_id": "dailycode-0da11b12c20540a69a7df7f71bc052af", + "node_id": "dailycode-f5007b90ce784459a128ea75d2f74143", "keywords": [], "children": [], "keywords_must": [], @@ -4179,7 +5206,7 @@ }, { "exercises": { - "node_id": "dailycode-a4f351932be94d9388ffb510d2ff8dc4", + "node_id": "dailycode-bdac8c45d3904849856e3a056ee32977", "keywords": [], "children": [], "keywords_must": [], @@ -4188,7 +5215,7 @@ }, { "exercises": { - "node_id": "dailycode-620f5bfe852e4cbd9ce5c2eb848eba27", + "node_id": "dailycode-7e632cf98b404ccba54e61ca0a59ca24", "keywords": [], "children": [], "keywords_must": [], @@ -4197,7 +5224,7 @@ }, { "exercises": { - "node_id": "dailycode-7c1a5ad714c441d7a0ccdee3c819e4c6", + "node_id": "dailycode-0c3fe32641404f16be867b3a3b4777a8", "keywords": [], "children": [], "keywords_must": [], @@ -4206,7 +5233,7 @@ }, { "exercises": { - "node_id": "dailycode-a51891de4bbd4992a1ca2d8d786bbc10", + "node_id": "dailycode-c35f1b8b4df24f2a9203047c0d6474c6", "keywords": [], "children": [], "keywords_must": [], @@ -4215,7 +5242,7 @@ }, { "exercises": { - "node_id": "dailycode-c1da5b7b32894b2691bf58b40188b67c", + "node_id": "dailycode-d806ed41ab324a0582401a2c7b2a3da7", "keywords": [], "children": [], "keywords_must": [], @@ -4224,7 +5251,7 @@ }, { "exercises": { - "node_id": "dailycode-6a33231763734cb28a58cca9e68d7ecd", + "node_id": "dailycode-178fdec62bcd41b0ab5d6d59b0ab1b74", "keywords": [], "children": [], "keywords_must": [], @@ -4233,7 +5260,7 @@ }, { "exercises": { - "node_id": "dailycode-d433cef163fe4e2fbdf5bef441506da8", + "node_id": "dailycode-38889c9cdaae42f4a0f4a8c8a9c710c4", "keywords": [], "children": [], "keywords_must": [], @@ -4242,7 +5269,7 @@ }, { "exercises": { - "node_id": "dailycode-7422725251434d6f802d5c3c67d3d8b2", + "node_id": "dailycode-3caea3b49b034e598bc0fbc44f533451", "keywords": [], "children": [], "keywords_must": [], @@ -4251,7 +5278,7 @@ }, { "exercises": { - "node_id": "dailycode-6007336fac224f659d45e9b3829c6726", + "node_id": "dailycode-b502a08a7c5c452b98a10f067e5ac1cb", "keywords": [], "children": [], "keywords_must": [], @@ -4260,7 +5287,7 @@ }, { "exercises": { - "node_id": "dailycode-bcd5c08f84344295bc2f185d6944f7c2", + "node_id": "dailycode-f705496a584747d69e1008f88a6e4bf8", "keywords": [], "children": [], "keywords_must": [], @@ -4269,7 +5296,7 @@ }, { "exercises": { - "node_id": "dailycode-16ecbc0a44ff4036aaf4be01fd07e40f", + "node_id": "dailycode-8f5f2e3476d345f0995743a1a93b93b5", "keywords": [], "children": [], "keywords_must": [], @@ -4278,7 +5305,7 @@ }, { "exercises": { - "node_id": "dailycode-b6ed4d3d6d31409fb7f1fcc072ce4295", + "node_id": "dailycode-6d9dbe9c0db5433dbf81e522dbfedeb0", "keywords": [], "children": [], "keywords_must": [], @@ -4287,7 +5314,7 @@ }, { "exercises": { - "node_id": "dailycode-06dec96ef4e941b5b10c3a4feae74ddb", + "node_id": "dailycode-fdb0c6ff79bb497cbb659d0c0cd3aa0e", "keywords": [], "children": [], "keywords_must": [], @@ -4296,7 +5323,7 @@ }, { "exercises": { - "node_id": "dailycode-ed11e080bba44d2bb7ec98bbddac3ffc", + "node_id": "dailycode-0a11733c91fa474bb7a32059c929f5f2", "keywords": [], "children": [], "keywords_must": [], @@ -4305,7 +5332,7 @@ }, { "exercises": { - "node_id": "dailycode-da11ba53a9bb4e6b8880a2cd184933d4", + "node_id": "dailycode-a80939d1f7bf47458f330cb20db27c6d", "keywords": [], "children": [], "keywords_must": [], @@ -4314,26 +5341,16 @@ }, { "exercises": { - "node_id": "dailycode-56e99b722b5641bc884da20f47a9386f", + "node_id": "dailycode-ab955e0c23904c6d8b3dd32fc4d80da1", "keywords": [], "children": [], "keywords_must": [], "keywords_forbid": [] } - } - ], - "keywords_must": [], - "keywords_forbid": [] - } - }, - { - "python": { - "node_id": "dailycode-6adb56f72172439c9d712de16b8d504c", - "keywords": [], - "children": [ + }, { "exercises": { - "node_id": "dailycode-c4bd91e863e346e8860401ab6914732e", + "node_id": "dailycode-9f59a4bafe424c768dc1883a7edfb04b", "keywords": [], "children": [], "keywords_must": [], @@ -4342,7 +5359,7 @@ }, { "exercises": { - "node_id": "dailycode-10743c3216c44bb1a4acda922204abf7", + "node_id": "dailycode-950e34d34dc94847975e1ca56e54c574", "keywords": [], "children": [], "keywords_must": [], @@ -4351,7 +5368,7 @@ }, { "exercises": { - "node_id": "dailycode-df5089b6b16346dcb5d24198a0eb1e37", + "node_id": "dailycode-9dc6613c2af04b408404e0c407aaa7c6", "keywords": [], "children": [], "keywords_must": [], @@ -4360,7 +5377,7 @@ }, { "exercises": { - "node_id": "dailycode-e255b434da964a3e8c1104d1242677a5", + "node_id": "dailycode-bc3eb1c20a03474e83551d80ab9725c7", "keywords": [], "children": [], "keywords_must": [], @@ -4369,7 +5386,7 @@ }, { "exercises": { - "node_id": "dailycode-d23d7c0418f84280a2ef890bb4fb1757", + "node_id": "dailycode-5e08f34544f041569745d22d11919871", "keywords": [], "children": [], "keywords_must": [], @@ -4378,7 +5395,7 @@ }, { "exercises": { - "node_id": "dailycode-a7329b367a72496381d22bcbc15b0ab1", + "node_id": "dailycode-6afc8fbcc3f245aeb6bfea64f87d53ee", "keywords": [], "children": [], "keywords_must": [], @@ -4387,7 +5404,7 @@ }, { "exercises": { - "node_id": "dailycode-b1f1ffa8aa944017bc6c7f4d7b9cece2", + "node_id": "dailycode-15dfcfc57f144a59b0745657fd22e7de", "keywords": [], "children": [], "keywords_must": [], @@ -4396,7 +5413,7 @@ }, { "exercises": { - "node_id": "dailycode-62b760478e454f309a425bf1da91ecd9", + "node_id": "dailycode-55947e6bb1d6408ca60413a7d03f7e38", "keywords": [], "children": [], "keywords_must": [], @@ -4405,7 +5422,7 @@ }, { "exercises": { - "node_id": "dailycode-527f1c40eca54c19be59eb9d93305dc3", + "node_id": "dailycode-c7d55f870c9244b6a627dcdd0e13dc35", "keywords": [], "children": [], "keywords_must": [], @@ -4414,7 +5431,7 @@ }, { "exercises": { - "node_id": "dailycode-69fd78974192450ebe5d6fe0bbdbfa67", + "node_id": "dailycode-a76adb81a0c14ce6ae16b18421469984", "keywords": [], "children": [], "keywords_must": [], @@ -4423,7 +5440,7 @@ }, { "exercises": { - "node_id": "dailycode-061ac0473af848a6aea1b1d7380686f7", + "node_id": "dailycode-f403ab092a4b4c709a21aaa49c497197", "keywords": [], "children": [], "keywords_must": [], @@ -4432,7 +5449,7 @@ }, { "exercises": { - "node_id": "dailycode-ebc866b086ae44a79c65cb99235a170a", + "node_id": "dailycode-026eee6137c34799ac0a1fe8e3cefc1a", "keywords": [], "children": [], "keywords_must": [], @@ -4441,7 +5458,7 @@ }, { "exercises": { - "node_id": "dailycode-0da6d95ed1b54b8e83d0193c88e6c237", + "node_id": "dailycode-71504d078d39443c801ae99bf0d81fa1", "keywords": [], "children": [], "keywords_must": [], @@ -4450,7 +5467,7 @@ }, { "exercises": { - "node_id": "dailycode-89a4d210cf6b4a96ab49088e293fdd9f", + "node_id": "dailycode-7a8871cf181c497388f30abbc0b603d9", "keywords": [], "children": [], "keywords_must": [], @@ -4459,7 +5476,7 @@ }, { "exercises": { - "node_id": "dailycode-74272d3291224f24af9d13e734d733f5", + "node_id": "dailycode-054c08399a624f7b823f3b8f5f4e612b", "keywords": [], "children": [], "keywords_must": [], @@ -4468,7 +5485,7 @@ }, { "exercises": { - "node_id": "dailycode-1cb29400682c421faa8d5b7cb588faef", + "node_id": "dailycode-27bae4c0ba27468eb2c6e09a7251d16d", "keywords": [], "children": [], "keywords_must": [], @@ -4477,7 +5494,7 @@ }, { "exercises": { - "node_id": "dailycode-fe3d45a08a0f47858df48e044d0ae2f9", + "node_id": "dailycode-a8944f7f59b943228d64d83b7428caa0", "keywords": [], "children": [], "keywords_must": [], @@ -4486,7 +5503,7 @@ }, { "exercises": { - "node_id": "dailycode-8c22cff947234df7a45ae4e553106499", + "node_id": "dailycode-305b624c7612402fa0b7c7c2464694cc", "keywords": [], "children": [], "keywords_must": [], @@ -4495,7 +5512,7 @@ }, { "exercises": { - "node_id": "dailycode-3e9f6ff35d514b77a9785d61386e9093", + "node_id": "dailycode-27c2c1b4db8748f394d7ec612bf0ac33", "keywords": [], "children": [], "keywords_must": [], @@ -4504,7 +5521,7 @@ }, { "exercises": { - "node_id": "dailycode-f5007b90ce784459a128ea75d2f74143", + "node_id": "dailycode-00212162ec234e81a8f9274d7c9a85d2", "keywords": [], "children": [], "keywords_must": [], @@ -4513,7 +5530,7 @@ }, { "exercises": { - "node_id": "dailycode-bdac8c45d3904849856e3a056ee32977", + "node_id": "dailycode-671c6173f6cf4b489c1cd9bee0cca519", "keywords": [], "children": [], "keywords_must": [], @@ -4522,7 +5539,7 @@ }, { "exercises": { - "node_id": "dailycode-7e632cf98b404ccba54e61ca0a59ca24", + "node_id": "dailycode-237fc188faa44250a488a2ae809d34e8", "keywords": [], "children": [], "keywords_must": [], @@ -4531,7 +5548,7 @@ }, { "exercises": { - "node_id": "dailycode-0c3fe32641404f16be867b3a3b4777a8", + "node_id": "dailycode-6248a779002b4454b3493e7553b99d49", "keywords": [], "children": [], "keywords_must": [], @@ -4540,7 +5557,7 @@ }, { "exercises": { - "node_id": "dailycode-c35f1b8b4df24f2a9203047c0d6474c6", + "node_id": "dailycode-a23959a66506488a952c2aace7627c39", "keywords": [], "children": [], "keywords_must": [], @@ -4549,7 +5566,7 @@ }, { "exercises": { - "node_id": "dailycode-d806ed41ab324a0582401a2c7b2a3da7", + "node_id": "dailycode-3ea29a0e480449b6afcf0106f48e3d83", "keywords": [], "children": [], "keywords_must": [], @@ -4558,7 +5575,7 @@ }, { "exercises": { - "node_id": "dailycode-178fdec62bcd41b0ab5d6d59b0ab1b74", + "node_id": "dailycode-325bf433414c4b698ce5e6ec41e1a44d", "keywords": [], "children": [], "keywords_must": [], @@ -4567,16 +5584,36 @@ }, { "exercises": { - "node_id": "dailycode-38889c9cdaae42f4a0f4a8c8a9c710c4", + "node_id": "dailycode-ce77e5bfde1d4560969cbcbafc93a241", "keywords": [], "children": [], "keywords_must": [], "keywords_forbid": [] } - }, + } + ], + "keywords_must": [], + "keywords_forbid": [] + } + } + ], + "keywords_must": [], + "keywords_forbid": [] + } + }, + { + "dailycode高阶": { + "node_id": "dailycode-fb69ab6a31c34ad4b5ba4f2869c27f75", + "keywords": [], + "children": [ + { + "cpp": { + "node_id": "dailycode-0da5ab41a68f4658b9965dc98958684d", + "keywords": [], + "children": [ { "exercises": { - "node_id": "dailycode-3caea3b49b034e598bc0fbc44f533451", + "node_id": "dailycode-b6d28853f68d4a5c842f4d1329b51b95", "keywords": [], "children": [], "keywords_must": [], @@ -4585,7 +5622,7 @@ }, { "exercises": { - "node_id": "dailycode-b502a08a7c5c452b98a10f067e5ac1cb", + "node_id": "dailycode-11c2226bae91486682a9bd27df4047b5", "keywords": [], "children": [], "keywords_must": [], @@ -4594,7 +5631,7 @@ }, { "exercises": { - "node_id": "dailycode-f705496a584747d69e1008f88a6e4bf8", + "node_id": "dailycode-f77c8eab81bd4f33b5a86ef896683c1a", "keywords": [], "children": [], "keywords_must": [], @@ -4603,7 +5640,7 @@ }, { "exercises": { - "node_id": "dailycode-8f5f2e3476d345f0995743a1a93b93b5", + "node_id": "dailycode-f65da56d7cc24a039bf82c904df55f58", "keywords": [], "children": [], "keywords_must": [], @@ -4612,7 +5649,7 @@ }, { "exercises": { - "node_id": "dailycode-6d9dbe9c0db5433dbf81e522dbfedeb0", + "node_id": "dailycode-70c36c9a7d99475c87b427df4b2fe285", "keywords": [], "children": [], "keywords_must": [], @@ -4621,7 +5658,7 @@ }, { "exercises": { - "node_id": "dailycode-fdb0c6ff79bb497cbb659d0c0cd3aa0e", + "node_id": "dailycode-5796b5e24b034f8485f278d8ea6b2674", "keywords": [], "children": [], "keywords_must": [], @@ -4630,7 +5667,7 @@ }, { "exercises": { - "node_id": "dailycode-0a11733c91fa474bb7a32059c929f5f2", + "node_id": "dailycode-78ef1609cd054f0e8405c97d76ef6dfa", "keywords": [], "children": [], "keywords_must": [], @@ -4639,7 +5676,7 @@ }, { "exercises": { - "node_id": "dailycode-a80939d1f7bf47458f330cb20db27c6d", + "node_id": "dailycode-7798b34864d141ac9f37b317b0907ceb", "keywords": [], "children": [], "keywords_must": [], @@ -4648,7 +5685,7 @@ }, { "exercises": { - "node_id": "dailycode-ab955e0c23904c6d8b3dd32fc4d80da1", + "node_id": "dailycode-3224725bf9304f5ea5f91480fa9bc974", "keywords": [], "children": [], "keywords_must": [], @@ -4657,7 +5694,7 @@ }, { "exercises": { - "node_id": "dailycode-9f59a4bafe424c768dc1883a7edfb04b", + "node_id": "dailycode-4e0793b3767449d58122e2c9a97f0bac", "keywords": [], "children": [], "keywords_must": [], @@ -4666,7 +5703,7 @@ }, { "exercises": { - "node_id": "dailycode-950e34d34dc94847975e1ca56e54c574", + "node_id": "dailycode-43ca27b263d047aebb7b4cb0e86d7f8a", "keywords": [], "children": [], "keywords_must": [], @@ -4675,7 +5712,7 @@ }, { "exercises": { - "node_id": "dailycode-9dc6613c2af04b408404e0c407aaa7c6", + "node_id": "dailycode-ea953e17f9ec4cd7aa1341f7892c60f6", "keywords": [], "children": [], "keywords_must": [], @@ -4684,7 +5721,7 @@ }, { "exercises": { - "node_id": "dailycode-bc3eb1c20a03474e83551d80ab9725c7", + "node_id": "dailycode-c11894f51cc0474ba829f36a11133691", "keywords": [], "children": [], "keywords_must": [], @@ -4693,7 +5730,7 @@ }, { "exercises": { - "node_id": "dailycode-5e08f34544f041569745d22d11919871", + "node_id": "dailycode-8190a9a91ce54eef9e371ce1dcecad04", "keywords": [], "children": [], "keywords_must": [], @@ -4702,7 +5739,7 @@ }, { "exercises": { - "node_id": "dailycode-6afc8fbcc3f245aeb6bfea64f87d53ee", + "node_id": "dailycode-4dd43c582c5f499b9f30071512adce42", "keywords": [], "children": [], "keywords_must": [], @@ -4711,7 +5748,7 @@ }, { "exercises": { - "node_id": "dailycode-15dfcfc57f144a59b0745657fd22e7de", + "node_id": "dailycode-9a4408230ad9414ca2c6ae393d6dfc0c", "keywords": [], "children": [], "keywords_must": [], @@ -4720,7 +5757,7 @@ }, { "exercises": { - "node_id": "dailycode-55947e6bb1d6408ca60413a7d03f7e38", + "node_id": "dailycode-ef701b1245294488a29c1d7609ccc901", "keywords": [], "children": [], "keywords_must": [], @@ -4729,7 +5766,7 @@ }, { "exercises": { - "node_id": "dailycode-c7d55f870c9244b6a627dcdd0e13dc35", + "node_id": "dailycode-c03b1ceef1b24852b191ba1208ae6903", "keywords": [], "children": [], "keywords_must": [], @@ -4738,7 +5775,7 @@ }, { "exercises": { - "node_id": "dailycode-a76adb81a0c14ce6ae16b18421469984", + "node_id": "dailycode-931e77e54385459da6bd004f6f13b187", "keywords": [], "children": [], "keywords_must": [], @@ -4747,7 +5784,7 @@ }, { "exercises": { - "node_id": "dailycode-f403ab092a4b4c709a21aaa49c497197", + "node_id": "dailycode-12154716a86a4a3996629c7ffe33e922", "keywords": [], "children": [], "keywords_must": [], @@ -4756,7 +5793,7 @@ }, { "exercises": { - "node_id": "dailycode-026eee6137c34799ac0a1fe8e3cefc1a", + "node_id": "dailycode-6c1fc61550b048c696cf72b285cbca33", "keywords": [], "children": [], "keywords_must": [], @@ -4765,7 +5802,7 @@ }, { "exercises": { - "node_id": "dailycode-71504d078d39443c801ae99bf0d81fa1", + "node_id": "dailycode-379fe0110ce244ed9109860976c01206", "keywords": [], "children": [], "keywords_must": [], @@ -4774,7 +5811,7 @@ }, { "exercises": { - "node_id": "dailycode-7a8871cf181c497388f30abbc0b603d9", + "node_id": "dailycode-71a29d2d4ba84ef5862dbcd1547a8d0c", "keywords": [], "children": [], "keywords_must": [], @@ -4783,7 +5820,7 @@ }, { "exercises": { - "node_id": "dailycode-054c08399a624f7b823f3b8f5f4e612b", + "node_id": "dailycode-ec2dc76044e44a3ca30eabe97355ea63", "keywords": [], "children": [], "keywords_must": [], @@ -4792,7 +5829,7 @@ }, { "exercises": { - "node_id": "dailycode-27bae4c0ba27468eb2c6e09a7251d16d", + "node_id": "dailycode-4522f669896d4e32bae4b5a741d160ad", "keywords": [], "children": [], "keywords_must": [], @@ -4801,7 +5838,7 @@ }, { "exercises": { - "node_id": "dailycode-a8944f7f59b943228d64d83b7428caa0", + "node_id": "dailycode-569fed9589644294ae5ef549b7babf31", "keywords": [], "children": [], "keywords_must": [], @@ -4810,7 +5847,7 @@ }, { "exercises": { - "node_id": "dailycode-305b624c7612402fa0b7c7c2464694cc", + "node_id": "dailycode-9f07bfe91c6f4ca484f92a7a49912a66", "keywords": [], "children": [], "keywords_must": [], @@ -4819,7 +5856,7 @@ }, { "exercises": { - "node_id": "dailycode-27c2c1b4db8748f394d7ec612bf0ac33", + "node_id": "dailycode-b7c191c627974320b5a16024eb016358", "keywords": [], "children": [], "keywords_must": [], @@ -4828,7 +5865,7 @@ }, { "exercises": { - "node_id": "dailycode-00212162ec234e81a8f9274d7c9a85d2", + "node_id": "dailycode-a1becf27311a4e77a4c9cc59c8847eef", "keywords": [], "children": [], "keywords_must": [], @@ -4837,7 +5874,7 @@ }, { "exercises": { - "node_id": "dailycode-671c6173f6cf4b489c1cd9bee0cca519", + "node_id": "dailycode-4cfdb4abcc864c1ba3c3b08cc1884f6b", "keywords": [], "children": [], "keywords_must": [], @@ -4846,7 +5883,7 @@ }, { "exercises": { - "node_id": "dailycode-237fc188faa44250a488a2ae809d34e8", + "node_id": "dailycode-9c4fc46e655e473c8b1fa86ebaa44589", "keywords": [], "children": [], "keywords_must": [], @@ -4855,7 +5892,7 @@ }, { "exercises": { - "node_id": "dailycode-6248a779002b4454b3493e7553b99d49", + "node_id": "dailycode-7568d52f35704930b597b69901e61ae6", "keywords": [], "children": [], "keywords_must": [], @@ -4864,7 +5901,7 @@ }, { "exercises": { - "node_id": "dailycode-a23959a66506488a952c2aace7627c39", + "node_id": "dailycode-da88752f950b47bdbbb804a8ce1489c0", "keywords": [], "children": [], "keywords_must": [], @@ -4873,7 +5910,7 @@ }, { "exercises": { - "node_id": "dailycode-3ea29a0e480449b6afcf0106f48e3d83", + "node_id": "dailycode-26802d77cb99478bbd3754edb14e4d05", "keywords": [], "children": [], "keywords_must": [], @@ -4882,7 +5919,7 @@ }, { "exercises": { - "node_id": "dailycode-325bf433414c4b698ce5e6ec41e1a44d", + "node_id": "dailycode-a84cd69409ca4eb6b4ce004ce6cb68f4", "keywords": [], "children": [], "keywords_must": [], @@ -4891,36 +5928,16 @@ }, { "exercises": { - "node_id": "dailycode-ce77e5bfde1d4560969cbcbafc93a241", + "node_id": "dailycode-614de2b516c846b88756982c0408dde8", "keywords": [], "children": [], "keywords_must": [], "keywords_forbid": [] } - } - ], - "keywords_must": [], - "keywords_forbid": [] - } - } - ], - "keywords_must": [], - "keywords_forbid": [] - } - }, - { - "dailycode高阶": { - "node_id": "dailycode-fb69ab6a31c34ad4b5ba4f2869c27f75", - "keywords": [], - "children": [ - { - "cpp": { - "node_id": "dailycode-0da5ab41a68f4658b9965dc98958684d", - "keywords": [], - "children": [ + }, { "exercises": { - "node_id": "dailycode-b6d28853f68d4a5c842f4d1329b51b95", + "node_id": "dailycode-d1dc9f58aa4b411886252ef1dbc58060", "keywords": [], "children": [], "keywords_must": [], @@ -4929,7 +5946,7 @@ }, { "exercises": { - "node_id": "dailycode-11c2226bae91486682a9bd27df4047b5", + "node_id": "dailycode-29a75c30bfa34e84a2c372b6e931a7a5", "keywords": [], "children": [], "keywords_must": [], @@ -4938,7 +5955,7 @@ }, { "exercises": { - "node_id": "dailycode-f77c8eab81bd4f33b5a86ef896683c1a", + "node_id": "dailycode-eef9a0612cff417fbb8eb4fedfb899db", "keywords": [], "children": [], "keywords_must": [], @@ -4947,7 +5964,7 @@ }, { "exercises": { - "node_id": "dailycode-f65da56d7cc24a039bf82c904df55f58", + "node_id": "dailycode-3a1bc738c17a4209a24f20e6284146dd", "keywords": [], "children": [], "keywords_must": [], @@ -4956,7 +5973,7 @@ }, { "exercises": { - "node_id": "dailycode-70c36c9a7d99475c87b427df4b2fe285", + "node_id": "dailycode-20b092dea834439fb605c1749d6e268b", "keywords": [], "children": [], "keywords_must": [], @@ -4965,7 +5982,7 @@ }, { "exercises": { - "node_id": "dailycode-5796b5e24b034f8485f278d8ea6b2674", + "node_id": "dailycode-b21a1bcfe07c466d894abf1624a2e27b", "keywords": [], "children": [], "keywords_must": [], @@ -4974,7 +5991,7 @@ }, { "exercises": { - "node_id": "dailycode-78ef1609cd054f0e8405c97d76ef6dfa", + "node_id": "dailycode-d58de695f661474f8a2f72bf151c32f4", "keywords": [], "children": [], "keywords_must": [], @@ -4983,7 +6000,7 @@ }, { "exercises": { - "node_id": "dailycode-7798b34864d141ac9f37b317b0907ceb", + "node_id": "dailycode-d92de43caa3540a4b5aa693d35035468", "keywords": [], "children": [], "keywords_must": [], @@ -4992,7 +6009,7 @@ }, { "exercises": { - "node_id": "dailycode-3224725bf9304f5ea5f91480fa9bc974", + "node_id": "dailycode-98daf8a40cf94f16b451b22387358559", "keywords": [], "children": [], "keywords_must": [], @@ -5001,7 +6018,7 @@ }, { "exercises": { - "node_id": "dailycode-4e0793b3767449d58122e2c9a97f0bac", + "node_id": "dailycode-623ee98952304b7e9b919c3d7e146a19", "keywords": [], "children": [], "keywords_must": [], @@ -5010,7 +6027,7 @@ }, { "exercises": { - "node_id": "dailycode-43ca27b263d047aebb7b4cb0e86d7f8a", + "node_id": "dailycode-37990a05873740ab861f20f4e78be70b", "keywords": [], "children": [], "keywords_must": [], @@ -5019,7 +6036,7 @@ }, { "exercises": { - "node_id": "dailycode-ea953e17f9ec4cd7aa1341f7892c60f6", + "node_id": "dailycode-dc71d0ff18eb49d79792f969fe3e4e12", "keywords": [], "children": [], "keywords_must": [], @@ -5028,7 +6045,7 @@ }, { "exercises": { - "node_id": "dailycode-c11894f51cc0474ba829f36a11133691", + "node_id": "dailycode-19c4d2ed874a4229bed1cfffb35fa37c", "keywords": [], "children": [], "keywords_must": [], @@ -5037,7 +6054,7 @@ }, { "exercises": { - "node_id": "dailycode-8190a9a91ce54eef9e371ce1dcecad04", + "node_id": "dailycode-16b098a417204953a4caabb304f6db9f", "keywords": [], "children": [], "keywords_must": [], @@ -5046,7 +6063,7 @@ }, { "exercises": { - "node_id": "dailycode-4dd43c582c5f499b9f30071512adce42", + "node_id": "dailycode-d7a599592aa24aff848013c6ec15cf10", "keywords": [], "children": [], "keywords_must": [], @@ -5055,7 +6072,7 @@ }, { "exercises": { - "node_id": "dailycode-9a4408230ad9414ca2c6ae393d6dfc0c", + "node_id": "dailycode-296ab2fd88934525b5653ef7114a0358", "keywords": [], "children": [], "keywords_must": [], @@ -5064,7 +6081,7 @@ }, { "exercises": { - "node_id": "dailycode-ef701b1245294488a29c1d7609ccc901", + "node_id": "dailycode-4aeca3661ce143d0bbfd73f6e72f11e9", "keywords": [], "children": [], "keywords_must": [], @@ -5073,7 +6090,7 @@ }, { "exercises": { - "node_id": "dailycode-c03b1ceef1b24852b191ba1208ae6903", + "node_id": "dailycode-ab7610050b14427bb38fe76c6e8710c5", "keywords": [], "children": [], "keywords_must": [], @@ -5082,7 +6099,7 @@ }, { "exercises": { - "node_id": "dailycode-931e77e54385459da6bd004f6f13b187", + "node_id": "dailycode-cd6a68f0c68849f2be19d401b84309db", "keywords": [], "children": [], "keywords_must": [], @@ -5091,7 +6108,7 @@ }, { "exercises": { - "node_id": "dailycode-12154716a86a4a3996629c7ffe33e922", + "node_id": "dailycode-572dd30849c445fe93450dec47c48694", "keywords": [], "children": [], "keywords_must": [], @@ -5100,7 +6117,7 @@ }, { "exercises": { - "node_id": "dailycode-6c1fc61550b048c696cf72b285cbca33", + "node_id": "dailycode-88bbdbf9e14241978caed8e0c240060b", "keywords": [], "children": [], "keywords_must": [], @@ -5109,7 +6126,7 @@ }, { "exercises": { - "node_id": "dailycode-379fe0110ce244ed9109860976c01206", + "node_id": "dailycode-61f9fc10dc864281b7a95db6089242dd", "keywords": [], "children": [], "keywords_must": [], @@ -5118,7 +6135,7 @@ }, { "exercises": { - "node_id": "dailycode-71a29d2d4ba84ef5862dbcd1547a8d0c", + "node_id": "dailycode-7a317eb4490c473090a047305ef60283", "keywords": [], "children": [], "keywords_must": [], @@ -5127,7 +6144,7 @@ }, { "exercises": { - "node_id": "dailycode-ec2dc76044e44a3ca30eabe97355ea63", + "node_id": "dailycode-25cba8fca30740af8a49256efbf594cb", "keywords": [], "children": [], "keywords_must": [], @@ -5136,7 +6153,7 @@ }, { "exercises": { - "node_id": "dailycode-4522f669896d4e32bae4b5a741d160ad", + "node_id": "dailycode-9148dd1d0d824227a0f66243065d8d5e", "keywords": [], "children": [], "keywords_must": [], @@ -5145,7 +6162,7 @@ }, { "exercises": { - "node_id": "dailycode-569fed9589644294ae5ef549b7babf31", + "node_id": "dailycode-ed64cc102b034228bec7cdbf38c44a99", "keywords": [], "children": [], "keywords_must": [], @@ -5154,7 +6171,7 @@ }, { "exercises": { - "node_id": "dailycode-9f07bfe91c6f4ca484f92a7a49912a66", + "node_id": "dailycode-b8f9e08b8157416f913906073262a9c6", "keywords": [], "children": [], "keywords_must": [], @@ -5163,7 +6180,7 @@ }, { "exercises": { - "node_id": "dailycode-b7c191c627974320b5a16024eb016358", + "node_id": "dailycode-19e15a33245e42a0b1aa4c31ee5dc348", "keywords": [], "children": [], "keywords_must": [], @@ -5172,7 +6189,7 @@ }, { "exercises": { - "node_id": "dailycode-a1becf27311a4e77a4c9cc59c8847eef", + "node_id": "dailycode-f41308ed84bb4ef8ad09e564348c103f", "keywords": [], "children": [], "keywords_must": [], @@ -5181,7 +6198,7 @@ }, { "exercises": { - "node_id": "dailycode-4cfdb4abcc864c1ba3c3b08cc1884f6b", + "node_id": "dailycode-d574cf192da6469f948a09a9d97a071a", "keywords": [], "children": [], "keywords_must": [], @@ -5190,7 +6207,7 @@ }, { "exercises": { - "node_id": "dailycode-9c4fc46e655e473c8b1fa86ebaa44589", + "node_id": "dailycode-d2a1b7ad02a34771b7a2f90f7a9ea1ca", "keywords": [], "children": [], "keywords_must": [], @@ -5199,7 +6216,7 @@ }, { "exercises": { - "node_id": "dailycode-7568d52f35704930b597b69901e61ae6", + "node_id": "dailycode-e8d6d5215fc946fe8126be057a8f33bf", "keywords": [], "children": [], "keywords_must": [], @@ -5208,7 +6225,7 @@ }, { "exercises": { - "node_id": "dailycode-da88752f950b47bdbbb804a8ce1489c0", + "node_id": "dailycode-3f5b93af46c448b8ae7f658f71441265", "keywords": [], "children": [], "keywords_must": [], @@ -5217,7 +6234,7 @@ }, { "exercises": { - "node_id": "dailycode-26802d77cb99478bbd3754edb14e4d05", + "node_id": "dailycode-2ccf8bd80a7549a88c59b83b0a4784cc", "keywords": [], "children": [], "keywords_must": [], @@ -5226,7 +6243,7 @@ }, { "exercises": { - "node_id": "dailycode-a84cd69409ca4eb6b4ce004ce6cb68f4", + "node_id": "dailycode-cbca99701aee469abf36e38ed0f2f36e", "keywords": [], "children": [], "keywords_must": [], @@ -5235,7 +6252,7 @@ }, { "exercises": { - "node_id": "dailycode-614de2b516c846b88756982c0408dde8", + "node_id": "dailycode-71f21c0d662d4ea3a6d46384c908cce6", "keywords": [], "children": [], "keywords_must": [], @@ -5244,7 +6261,7 @@ }, { "exercises": { - "node_id": "dailycode-d1dc9f58aa4b411886252ef1dbc58060", + "node_id": "dailycode-fbeb14ccb2ad450f92f803197d8a2898", "keywords": [], "children": [], "keywords_must": [], @@ -5253,7 +6270,7 @@ }, { "exercises": { - "node_id": "dailycode-29a75c30bfa34e84a2c372b6e931a7a5", + "node_id": "dailycode-42f27fdeec37424a8f341b005c5817ad", "keywords": [], "children": [], "keywords_must": [], @@ -5262,7 +6279,7 @@ }, { "exercises": { - "node_id": "dailycode-eef9a0612cff417fbb8eb4fedfb899db", + "node_id": "dailycode-aef821a970104bb790aa7151f2738112", "keywords": [], "children": [], "keywords_must": [], @@ -5271,7 +6288,7 @@ }, { "exercises": { - "node_id": "dailycode-3a1bc738c17a4209a24f20e6284146dd", + "node_id": "dailycode-a90c9ada239046bca1194d2abb4df6c4", "keywords": [], "children": [], "keywords_must": [], diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/102.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/102.exercises/solution.md" index d53e11db0e95d73ea7a2c6a403d0759953ad4ced..e954232106001d2365def6b27a8da24819df5dc4 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/102.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/102.exercises/solution.md" @@ -29,7 +29,48 @@ ## template ```cpp - +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + + +class Solution +{ +public: + vector> levelOrder(TreeNode *root) + { + if (root == NULL) + return {}; + queue queue; + TreeNode *p = root; + vector> res; + queue.push(p); + while (queue.empty() == false) + { + vector temp = {}; + int length = queue.size(); + for (int i = 0; i < length; i++) + { + p = queue.front(); + queue.pop(); + temp.push_back(p->val); + if (p->left) + queue.push(p->left); + if (p->right) + queue.push(p->right); + } + res.push_back(temp); + } + return res; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/103.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/103.exercises/solution.md" index 6f1786131e8db1d6f76f359c3c2855bf70e7605e..9d0d8c5b066fb0c4d4f518a40296b600a699449c 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/103.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/103.exercises/solution.md" @@ -27,6 +27,53 @@ ## template ```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + vector> zigzagLevelOrder(TreeNode *root) + { + if (!root) + return {}; + vector> res; + vector temp; + int level = 0; + queue> q; + q.push(pair(root, 0)); + while (!q.empty()) + { + TreeNode *node = q.front().first; + level = q.front().second; + q.pop(); + if (res.size() < level) + { + if (level % 2 == 0) + reverse(temp.begin(), temp.end()); + res.push_back(temp); + temp.clear(); + } + temp.push_back(node->val); + if (node->left) + q.push(pair(node->left, level + 1)); + if (node->right) + q.push(pair(node->right, level + 1)); + } + if (level % 2 != 0) + reverse(temp.begin(), temp.end()); + res.push_back(temp); + return res; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/105.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/105.exercises/solution.md" index 80626065a816c990fd264cdaeaee5ffc9592ed98..5469faf018853f2bdebfddcec127ae5a14c83dab 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/105.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/105.exercises/solution.md" @@ -36,7 +36,48 @@ ## template ```cpp - +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +private: + unordered_map inMap; + +public: + TreeNode *myBuildTree(vector &preorder, int preStart, int preEnd, vector &inorder, int inStart, int inEnd) + { + if (preStart > preEnd) + return nullptr; + + TreeNode *root = new TreeNode(preorder[preStart]); + + int inRoot = inMap[preorder[preStart]]; + int numsLeft = inRoot - inStart; + + root->left = myBuildTree(preorder, preStart + 1, preStart + numsLeft, inorder, inStart, inRoot - 1); + root->right = myBuildTree(preorder, preStart + numsLeft + 1, preEnd, inorder, inRoot + 1, inEnd); + return root; + } + + TreeNode *buildTree(vector &preorder, vector &inorder) + { + int n = preorder.size(); + for (int i = 0; i < n; i++) + { + inMap[inorder[i]] = i; + } + return myBuildTree(preorder, 0, n - 1, inorder, 0, n - 1); + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/106.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/106.exercises/solution.md" index b4b031d205951ee4d78f9e7ead48e66a9ae49526..9a6d528ea366b43446eb596571ed8fe60b28ac95 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/106.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/106.exercises/solution.md" @@ -23,7 +23,50 @@ ## template ```cpp - +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + TreeNode *buildTree(vector &inorder, vector &postorder) + { + if (0 == inorder.size() || 0 == postorder.size()) + { + return NULL; + } + return build(inorder, 0, inorder.size() - 1, postorder, 0, postorder.size() - 1); + } + + TreeNode *build(vector &inorder, int i1, int i2, vector &postorder, int p1, int p2) + { + TreeNode *root = new TreeNode(postorder[p2]); + int i = i1; + while (i <= i2 && postorder[p2] != inorder[i]) + { + i++; + } + int left = i - i1; + int right = i2 - i; + if (left > 0) + { + root->left = build(inorder, i1, i - 1, postorder, p1, p1 + left - 1); + } + if (right > 0) + { + root->right = build(inorder, i + 1, i2, postorder, p1 + left, p2 - 1); + } + return root; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/107.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/107.exercises/solution.md" index 6e917928a2ba31e4d934aab7050c3d23449331b0..80df184b406de92269f34efb7d7829a5236ec2ec 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/107.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/107.exercises/solution.md" @@ -27,7 +27,48 @@ ## template ```cpp - +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + + +class Solution +{ +public: + vector> levelOrderBottom(TreeNode *root) + { + + vector> res; + if (root == NULL) + return res; + queue q; + q.push(root); + while (!q.empty()) + { + vector oneLevel; + int size = q.size(); + for (int i = 0; i < size; i++) + { + TreeNode *node = q.front(); + q.pop(); + oneLevel.push_back(node->val); + if (node->left) + q.push(node->left); + if (node->right) + q.push(node->right); + } + res.insert(res.begin(), oneLevel); + } + return res; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/109.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/109.exercises/solution.md" index 1a230aa1cca742225adf3a4069254546f6aa2f94..ebdba906174f4a9f9a9aa162af192a6bab8934da 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/109.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/109.exercises/solution.md" @@ -21,6 +21,49 @@ ## template ```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + vector nums; + TreeNode *create(int low, int high) + { + if (low > high) + return NULL; + int mid = (low + high) / 2; + auto root = new TreeNode(nums[mid]); + root->left = create(low, mid - 1); + root->right = create(mid + 1, high); + return root; + } + TreeNode *sortedListToBST(ListNode *head) + { + while (head) + { + nums.push_back(head->val); + head = head->next; + } + + return create(0, nums.size() - 1); + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/113.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/113.exercises/solution.md" index d2834352aca20c24d1bd80cd530f082bffc51e34..c53bd9dc0e0f0c954a78940c10bd8c01f057b012 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/113.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/113.exercises/solution.md" @@ -45,6 +45,58 @@ ## template ```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + vector> pathSum(TreeNode *root, int sum) + { + vector> res; + vector track; + backTrack(root, res, track, sum); + return res; + } + + void backTrack(TreeNode *root, vector> &res, vector track, int sum) + { + + if (!root) + { + return; + } + if (!root->left && !root->right) + { + sum -= root->val; + track.push_back(root->val); + if (sum == 0) + { + res.push_back(track); + } + track.pop_back(); + sum += root->val; + return; + } + + sum -= root->val; + track.push_back(root->val); + + backTrack(root->left, res, track, sum); + backTrack(root->right, res, track, sum); + + track.pop_back(); + sum += root->val; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/114.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/114.exercises/solution.md" index 3f6c13c5d4c6e77509dfd61d89909348b451d607..dbe68d297b81c7133be5f5201b97783e8a6ca2a8 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/114.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/114.exercises/solution.md" @@ -47,7 +47,42 @@ ## template ```cpp - +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + void rconnect(TreeNode *&node, TreeNode *pmove) + { + if (pmove == nullptr) + return; + node->right = new TreeNode(pmove->val); + node->left = nullptr; + node = node->right; + rconnect(node, pmove->left); + rconnect(node, pmove->right); + } + void flatten(TreeNode *root) + { + if (root == nullptr) + return; + TreeNode *head = new TreeNode(); + TreeNode *newroot = head; + rconnect(head, root); + newroot = newroot->right->right; + root->right = newroot; + root->left = nullptr; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/116.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/116.exercises/solution.md" index 4e154b087ee31f31da7f7f23353d0ad726134eff..403d34145c1386c63bda2e345649675a35fee8c6 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/116.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/116.exercises/solution.md" @@ -48,7 +48,59 @@ struct Node { ## template ```cpp - +#include +using namespace std; + +class Node +{ +public: + int val; + Node *left; + Node *right; + Node *next; + Node() : val(0), left(NULL), right(NULL), next(NULL) {} + Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {} + Node(int _val, Node *_left, Node *_right, Node *_next) + : val(_val), left(_left), right(_right), next(_next) {} +}; + +class Solution +{ +public: + Node *connect(Node *root) + { + if (!root) + return nullptr; + + root->next = nullptr; + connect_helper(root); + + return root; + } + +private: + void connect_helper(Node *pNode) + { + if (!pNode) + return; + + if (pNode->left == nullptr) + return; + + pNode->left->next = pNode->right; + + if (pNode->right == nullptr) + return; + + if (pNode->next != nullptr) + pNode->right->next = pNode->next->left; + else + pNode->right->next = nullptr; + + connect_helper(pNode->left); + connect_helper(pNode->right); + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/117.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/117.exercises/solution.md" index 8a3944d3a50a07ea400b6e2a9dfb3de237d6e85d..d37f6b23bbfc07098e080ccad607cf2ca03127ad 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/117.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/117.exercises/solution.md" @@ -52,6 +52,53 @@ struct Node { ## template ```cpp +#include +using namespace std; + +class Node +{ +public: + int val; + Node *left; + Node *right; + Node *next; + Node() : val(0), left(NULL), right(NULL), next(NULL) {} + Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {} + Node(int _val, Node *_left, Node *_right, Node *_next) + : val(_val), left(_left), right(_right), next(_next) {} +}; + +class Solution +{ +public: + Node *connect(Node *root) + { + if (!root) + return NULL; + Node *p = root->next; + while (p) + { + if (p->left) + { + p = p->left; + break; + } + if (p->right) + { + p = p->right; + break; + } + p = p->next; + } + if (root->right) + root->right->next = p; + if (root->left) + root->left->next = root->right ? root->right : p; + connect(root->right); + connect(root->left); + return root; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/120.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/120.exercises/solution.md" index 25195dfdd65d9b63af260599a2b435c478b6793b..6baaa6197f8f41c4588af014979945381b420ce1 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/120.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/120.exercises/solution.md" @@ -49,7 +49,47 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int minimumTotal(vector> &triangle) + { + int n = triangle.size(); + if (n == 0) + return 0; + if (n == 1) + return triangle[0][0]; + vector> info(n, vector(n, 0)); + info[0][0] = triangle[0][0]; + for (int i = 1; i < n; ++i) + { + for (int j = 0; j <= i; ++j) + { + if (j == 0) + info[i][j] = triangle[i][j] + info[i - 1][j]; + else if (j == i) + info[i][j] = triangle[i][j] + info[i - 1][j - 1]; + else + { + int temp = info[i - 1][j] > info[i - 1][j - 1] ? info[i - 1][j - 1] : info[i - 1][j]; + info[i][j] = temp + triangle[i][j]; + } + } + } + int res = info[n - 1][0]; + for (int i = 0; i < n; ++i) + { + if (info[n - 1][i] < res) + { + res = info[n - 1][i]; + } + } + return res; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/128.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/128.exercises/solution.md" index 8daf544d6c8a5cfb01ed330ea2822e02c2d13705..fca772aec430ce905ff6fb4ea8286eaa83558cd5 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/128.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/128.exercises/solution.md" @@ -33,7 +33,44 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int longestConsecutive(vector &nums) + { + unordered_set s; + for (auto v : nums) + s.insert(v); + int res = 0; + for (auto v : nums) + { + if (s.find(v) != s.end()) + { + s.erase(v); + int temp = 1; + int cur = v; + while (s.find(cur - 1) != s.end()) + { + cur--; + s.erase(cur); + } + temp += v - cur; + cur = v; + while (s.find(cur + 1) != s.end()) + { + cur++; + s.erase(cur); + } + temp += cur - v; + res = max(res, temp); + } + } + return res; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/129.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/129.exercises/solution.md" index df7449e36a1070c9652152b5d93f0eb4b72cd446..436bf0907707e22ef63e184273ea432db94b2d54 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/129.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/129.exercises/solution.md" @@ -53,6 +53,59 @@ ## template ```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + int sumNumbers(TreeNode *root) + { + if (root == nullptr) + return 0; + int result = 0; + vector num; + vector temp; + digui(root, &num, &temp); + for (int i = 0; i < num.size(); i++) + { + result = result + num[i]; + } + return result; + } + void digui(TreeNode *root, vector *num, vector *temp) + { + temp->push_back(root->val); + if (root->left == nullptr && root->right == nullptr) + { + int sum = 0; + for (int i = temp->size() - 1; i >= 0; i--) + { + /*if (i==0 && (*temp)[0]==0) { + continue; + }*/ + int howi = (*temp)[i]; + sum = sum + howi * pow(10, (temp->size() - i - 1)); + } + num->push_back(sum); + temp->pop_back(); + return; + } + if (root->left) + digui(root->left, num, temp); + if (root->right) + digui(root->right, num, temp); + temp->pop_back(); + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/130.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/130.exercises/solution.md" index 4858474ea168d25de20a9af6c8b92b297d135d89..cd76118caaaa542366a9d3b83dc06b084409fe3b 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/130.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/130.exercises/solution.md" @@ -37,6 +37,69 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + int m, n; + void solve(vector> &board) + { + m = board.size(); + if (!m) + return; + n = board[0].size(); + if (!n) + return; + for (int i = 0; i < m; ++i) + { + if (i == 0 || i == m - 1) + { + for (int j = 0; j < n; ++j) + { + if (board[i][j] == 'O') + dfs(board, i, j); + } + } + else + { + if (board[i][0] == 'O') + dfs(board, i, 0); + if (board[i][n - 1] == 'O') + dfs(board, i, n - 1); + } + } + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; ++j) + { + if (board[i][j] == 'A') + board[i][j] = 'O'; + else + board[i][j] = 'X'; + } + } + void dfs(vector> &board, int i, int j) + { + board[i][j] = 'A'; + if (i - 1 < m && i - 1 >= 0 && j < n && j >= 0 && board[i - 1][j] == 'O') + { + dfs(board, i - 1, j); + } + if (i + 1 < m && i + 1 >= 0 && j < n && j >= 0 && board[i + 1][j] == 'O') + { + dfs(board, i + 1, j); + } + if (i < m && i >= 0 && j - 1 < n && j - 1 >= 0 && board[i][j - 1] == 'O') + { + dfs(board, i, j - 1); + } + if (i < m && i >= 0 && j + 1 < n && j + 1 >= 0 && board[i][j + 1] == 'O') + { + dfs(board, i, j + 1); + } + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/131.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/131.exercises/solution.md" index aefe09874b1d16ca7341db1e45339ab05806bd25..b8653cf5324782754e27531ed6c35eedfdbdc764 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/131.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/131.exercises/solution.md" @@ -33,7 +33,46 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + bool isPali(string s) + { + for (int i = 0; i < s.length() / 2; i++) + if (s[i] != s[s.length() - i - 1]) + return false; + return true; + } + + void dfs(vector> &ans, vector &tmp, int n, string s) + { + if (n == s.length()) + { + ans.push_back(tmp); + return; + } + for (int i = n; i < s.length(); i++) + { + if (isPali(s.substr(n, i - n + 1))) + { + tmp.push_back(s.substr(n, i - n + 1)); + dfs(ans, tmp, i + 1, s); + tmp.pop_back(); + } + } + } + + vector> partition(string s) + { + vector> ans; + vector tmp; + dfs(ans, tmp, 0, s); + return ans; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/133.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/133.exercises/solution.md" index 73eefac15bcfa70d0361aea5d412eea06152d232..89b5548bc69699af056d1511803de6abb3e61ac2 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/133.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/133.exercises/solution.md" @@ -74,6 +74,47 @@ ## template ```cpp +#include +using namespace std; + +class Node +{ +public: + int val; + vector neighbors; + + Node() {} + + Node(int _val, vector _neighbors) + { + val = _val; + neighbors = _neighbors; + } +}; + +class Solution +{ +public: + Node *cloneGraph(Node *node) + { + unordered_map m; + return helper(node, m); + } + Node *helper(Node *node, unordered_map &m) + { + if (!node) + return NULL; + if (m.count(node)) + return m[node]; + Node *clone = new Node(node->val); + m[node] = clone; + for (Node *neighbor : node->neighbors) + { + clone->neighbors.push_back(helper(neighbor, m)); + } + return clone; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/134.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/134.exercises/solution.md" index f69ee9005633223f3447f0b5caac094f1a4d570c..4786b640caf11260f7e7f9f1bb887428589394bc 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/134.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/134.exercises/solution.md" @@ -51,6 +51,34 @@ cost = [3,4,3] ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + int canCompleteCircuit(vector &gas, vector &cost) + { + int index = 0; + int sum = 0; + int csum = 0; + for (int i = 0; i < gas.size(); i++) + { + int temp = gas[i] - cost[i]; + sum += temp; + if (csum > 0) + { + csum += gas[i] - cost[i]; + } + else + { + csum = gas[i] - cost[i]; + index = i; + } + } + return sum >= 0 ? index : -1; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/137.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/137.exercises/solution.md" index c193040537d265422c8e42328ad34b7173531d39..9c0c0a45c1f7f91520adf83815a676fec8b012bb 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/137.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/137.exercises/solution.md" @@ -36,6 +36,39 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + int singleNumber(vector &nums) + { + sort(nums.begin(), nums.end()); + int res = 0; + int i = 0; + for (int j = 1; j < nums.size(); j++) + { + if (nums[j] != nums[i]) + { + if (j - i == 1) + { + res = nums[i]; + break; + } + else + { + i = j; + } + } + } + if (i == nums.size() - 1) + { + res = nums[i]; + } + return res; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/138.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/138.exercises/solution.md" index 5093375dba44e90ca49aa2e2c93bf6323678f74d..ff6fecccfc730f9f343ed12eecc8bfc021e7752d 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/138.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/138.exercises/solution.md" @@ -68,6 +68,60 @@ ## template ```cpp +#include +using namespace std; + +class Node +{ +public: + int val; + Node *next; + Node *random; + + Node() {} + + Node(int _val, Node *_next, Node *_random) + { + val = _val; + next = _next; + random = _random; + } +}; + +class Solution +{ +public: + Node *copyRandomList(Node *head) + { + std::map node_map; + std::vector node_vec; + Node *ptr = head; + int i = 0; + while (ptr) + { + + node_vec.push_back(new Node(ptr->val, NULL, NULL)); + node_map[ptr] = i; + ptr = ptr->next; + i++; + } + node_vec.push_back(0); + ptr = head; + i = 0; + while (ptr) + { + node_vec[i]->next = node_vec[i + 1]; + if (ptr->random) + { + int id = node_map[ptr->random]; + node_vec[i]->random = node_vec[id]; + } + ptr = ptr->next; + i++; + } + return node_vec[0]; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/139.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/139.exercises/solution.md" index 5be338e2c1d6c38a3623967b99226c01c2309424..9d33833a9a1e8b8b3d1323b49412da4da6f7137d 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/139.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/139.exercises/solution.md" @@ -34,7 +34,36 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + bool wordBreak(string s, vector &wordDict) + { + map tmp; + for (int i = 0; i < wordDict.size(); i++) + { + tmp[wordDict[i]]++; + } + int n = s.length(); + vector res(n + 1, false); + res[0] = true; + for (int i = 0; i <= n; i++) + { + for (int j = 0; j < i; j++) + { + if (res[j] && tmp[s.substr(j, i - j)]) + { + res[i] = true; + break; + } + } + } + return res[n]; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/142.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/142.exercises/solution.md" index dda2aa5231801568934e17b33346067afeecede1..d926ada5126c44532acd7b23a7d93420d2f33e2b 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/142.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/142.exercises/solution.md" @@ -58,6 +58,42 @@ ## template ```cpp +#include +using namespace std; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + ListNode *detectCycle(ListNode *head) + { + ListNode *slow, *fast, *p; + slow = fast = p = head; + while (fast && fast->next) + { + slow = slow->next; + fast = fast->next->next; + + if (slow == fast) + { + while (p != slow) + { + p = p->next; + slow = slow->next; + } + return p; + } + } + + return nullptr; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/143.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/143.exercises/solution.md" index d03efec1670c928fb46d8e3f4dfdb8c9ceea18d1..7872033b6dec78880fb797e5e033a2135f516c0f 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/143.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/143.exercises/solution.md" @@ -40,6 +40,56 @@ ## template ```cpp +#include +using namespace std; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + void reorderList(ListNode *head) + { + ListNode *l1 = head, *l2 = head; + ListNode *tep = head; + int len = 0; + while (tep) + { + len++; + tep = tep->next; + } + if (len <= 2) + return; + int len1 = len / 2 + len % 2; + int len2 = len / 2; + for (int i = 0; i < len1 - 1; i++) + { + head = head->next; + } + l2 = head->next; + head->next = nullptr; + head = l1; + stack stk; + while (l2) + { + stk.push(l2); + l2 = l2->next; + } + while (!stk.empty()) + { + tep = stk.top(); + stk.pop(); + tep->next = l1->next; + l1->next = tep; + l1 = tep->next; + } + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/146.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/146.exercises/solution.md" index 766a4957e1630855a203a5eca3b9e16218940759..b8c24e16f256f896055e481bafefab3cd668c5ef 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/146.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/146.exercises/solution.md" @@ -57,6 +57,68 @@ lRUCache.get(4); // 返回 4 ## template ```cpp +#include +using namespace std; + +class LRUCache +{ +private: + int _cap; + + list> cache; + + unordered_map>::iterator> umap; + +public: + LRUCache(int capacity) + { + _cap = capacity; + } + + int get(int key) + { + auto iter = umap.find(key); + if (iter == umap.end()) + return -1; + + pair kv = *umap[key]; + cache.erase(umap[key]); + cache.push_front(kv); + umap[key] = cache.begin(); + + return kv.second; + } + + void put(int key, int value) + { + auto iter = umap.find(key); + if (iter != umap.end()) + { + + cache.erase(umap[key]); + cache.push_front(make_pair(key, value)); + umap[key] = cache.begin(); + + return; + } + + if (cache.size() == _cap) + { + + auto iter = cache.back(); + umap.erase(iter.first); + cache.pop_back(); + + cache.push_front(make_pair(key, value)); + umap[key] = cache.begin(); + } + else + { + cache.push_front(make_pair(key, value)); + umap[key] = cache.begin(); + } + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/147.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/147.exercises/solution.md" index e0df215c1036372e32976b880b4e95740bf482f8..cd8e1e2b0a50a6d67db52790c849b328b4f08bc1 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/147.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/147.exercises/solution.md" @@ -34,6 +34,37 @@ ## template ```cpp +#include +using namespace std; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + ListNode *insertionSortList(ListNode *head) + { + ListNode *dummy = new ListNode(0, head); + ListNode + *prev = dummy, + *lastSorted = head, + *curr = head->next; + + while (curr) + { + lastSorted->next = curr->next; + curr->next = prev->next; + prev->next = curr; + curr = lastSorted->next; + } + return dummy->next; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/148.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/148.exercises/solution.md" index 9e9618105307c9fe8d2efae4546acde39d9bb618..517ce6fbefb4a2b49be2e2ba215c58a23f8f7a4b 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/148.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/148.exercises/solution.md" @@ -44,6 +44,63 @@ ## template ```cpp +#include +using namespace std; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + ListNode *sortList(ListNode *head) + { + return mergesort(head); + } + ListNode *mergesort(ListNode *node) + { + if (!node || !node->next) + return node; + ListNode *fast = node; + ListNode *slow = node; + ListNode *brek = node; + while (fast && fast->next) + { + fast = fast->next->next; + brek = slow; + slow = slow->next; + } + brek->next = nullptr; + ListNode *l1 = mergesort(node); + ListNode *l2 = mergesort(slow); + return merge(l1, l2); + } + ListNode *merge(ListNode *l1, ListNode *l2) + { + if (l1 == NULL) + { + return l2; + } + if (l2 == NULL) + { + return l1; + } + if (l1->val < l2->val) + { + l1->next = merge(l1->next, l2); + return l1; + } + else + { + l2->next = merge(l2->next, l1); + return l2; + } + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/150.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/150.exercises/solution.md" index 464ac5b74556c15cbeee2176acc2a45dc26d89a6..a6d1f9be85ca18aaef3c67d4c8cf421ab6dad598 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/150.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/150.exercises/solution.md" @@ -77,6 +77,42 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + int evalRPN(vector &tokens) + { + stack num; + for (int i = 0; i < tokens.size(); ++i) + { + if (tokens[i] == "+" || tokens[i] == "-" || tokens[i] == "*" || tokens[i] == "/") + { + int j; + int a = num.top(); + num.pop(); + int b = num.top(); + num.pop(); + if (tokens[i] == "+") + j = b + a; + else if (tokens[i] == "-") + j = b - a; + else if (tokens[i] == "*") + j = b * a; + else + j = b / a; + num.push(j); + } + else + { + num.push(stoi(tokens[i])); + } + } + return num.top(); + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/151.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/151.exercises/solution.md" index dcd3525f99120b8896c1f6dbb2b8ca8b6250af37..4c58948bd19e52958d3c9c068314af2e3bbd4bd7 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/151.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/151.exercises/solution.md" @@ -78,6 +78,58 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + string reverseWords(string s) + { + splitStr(s); + return joinStr(); + } + +private: + void splitStr(string s) + { + if (s == "") + return; + int len = s.length(); + string tmp = ""; + for (int i = 0; i < len; i++) + { + if (s[i] == ' ' && tmp != "") + { + myStack.push(tmp); + tmp = ""; + continue; + } + if (s[i] == ' ') + continue; + tmp += s[i]; + } + if (tmp != "") + myStack.push(tmp); + return; + } + + string joinStr() + { + if (myStack.empty()) + return ""; + string s = ""; + while (!myStack.empty()) + { + s += myStack.top(); + s += " "; + myStack.pop(); + } + return s.substr(0, s.length() - 1); + } + + stack myStack; +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/152.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/152.exercises/solution.md" index bd368c2b75bc79b0172b9d4c3edbdda9b708e41f..9bbd637cf9b2c929e18d1395e8ce7d52b8db4b1e 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/152.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/152.exercises/solution.md" @@ -21,6 +21,28 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + int maxProduct(vector &nums) + { + int ans = -10000000; + int n = nums.size(); + int max1 = 1, min1 = 1, mx, mn; + for (int i = 0; i < n; i++) + { + mx = max1; + mn = min1; + max1 = max(mx * nums[i], max(nums[i], mn * nums[i])); + min1 = min(mn * nums[i], min(nums[i], mx * nums[i])); + ans = max(max1, ans); + } + return ans; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/153.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/153.exercises/solution.md" index cffc94a1009f4db8334e36133d05c851c3ab76f7..b6e6404fe90e691802f0a68783768952456f25e5 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/153.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/153.exercises/solution.md" @@ -52,6 +52,27 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + int findMin(vector &nums) + { + int left = 0, right = nums.size() - 1; + int mid = (left + right) / 2; + while (left < right) + { + mid = (left + right) / 2; + if (nums[mid] > nums[right]) + left = mid + 1; + else + right = mid; + } + return nums[left]; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/156.exercises/solution.json" "b/data_source/exercises/\344\270\255\347\255\211/cpp/156.exercises/solution.json" deleted file mode 100644 index 0ea87659f8f10d474049f30118de5d2af345f7c4..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/156.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "d61ff566c89342b888c5df90a0fa5007", - "author": "csdn.net", - "keywords": "树,深度优先搜索,二叉树" -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/156.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/156.exercises/solution.md" deleted file mode 100644 index 955d3af0c07d29f3331bf5fecab2c57a86f22a39..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/156.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 上下翻转二叉树 - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/159.exercises/solution.json" "b/data_source/exercises/\344\270\255\347\255\211/cpp/159.exercises/solution.json" deleted file mode 100644 index 00be9678a726a2e41d3fc28ec233182353233210..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/159.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "12b418be49d0440d80d23d1498d77aea", - "author": "csdn.net", - "keywords": "哈希表,字符串,滑动窗口" -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/159.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/159.exercises/solution.md" deleted file mode 100644 index 3bd069a2fbe275ce5922a9893c170c841191a506..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/159.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 至多包含两个不同字符的最长子串 - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/161.exercises/solution.json" "b/data_source/exercises/\344\270\255\347\255\211/cpp/161.exercises/solution.json" deleted file mode 100644 index 23a50229cfba85e9838c6b6d3ab5bb37385a4e80..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/161.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "99f8cccc1b934f6e92b94a26f0ccc34c", - "author": "csdn.net", - "keywords": "双指针,字符串" -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/161.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/161.exercises/solution.md" deleted file mode 100644 index a15a284f147cdcc0b62da5938e1e2a5e954c38e5..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/161.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 相隔为 1 的编辑距离 - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/162.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/162.exercises/solution.md" index 6de4e110f46199c734cde7b81cba588c031d4e6d..355c99ca11d4bdc24bf2611bb9a5ef49cc839fd7 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/162.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/162.exercises/solution.md" @@ -41,6 +41,36 @@ ```cpp +#include +using namespace std; + +class Solution +{ +public: + int findPeakElement(vector &nums) + { + int l = 0, r = nums.size() - 1; + while (l < r) + { + int mid = l + (r - l) / 2; + if (nums[mid] > nums[mid + 1]) + { + if (mid == 0 || nums[mid] > nums[mid - 1]) + return mid; + else + r = mid; + } + else + { + if (mid + 1 == nums.size() - 1 || nums[mid + 1] > nums[mid + 2]) + return mid + 1; + else + l = mid + 1; + } + } + return l; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/165.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/165.exercises/solution.md" index 5c48c367321b3dd73d9d77ee1e87a2e4822af6e0..2fe69070c906edb350411139b58de6e28b0e0d6d 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/165.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/165.exercises/solution.md" @@ -69,7 +69,49 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int compareVersion(string version1, string version2) + { + int val1, val2; + int idx1 = 0, idx2 = 0; + while (idx1 < version1.length() || idx2 < version2.length()) + { + val1 = 0; + while (idx1 < version1.length()) + { + if (version1[idx1] == '.') + { + ++idx1; + break; + } + val1 = val1 * 10 + (version1[idx1] - '0'); + idx1++; + } + + val2 = 0; + while (idx2 < version2.length()) + { + if (version2[idx2] == '.') + { + idx2++; + break; + } + val2 = val2 * 10 + (version2[idx2] - '0'); + idx2++; + } + if (val1 > val2) + return 1; + if (val1 < val2) + return -1; + } + return 0; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/166.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/166.exercises/solution.md" index 77308bfe75426a407e96c904684a91aae472647f..0df460df108875a8eb98ee69ffa1c68996be4c06 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/166.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/166.exercises/solution.md" @@ -58,6 +58,47 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + string fractionToDecimal(int numerator, int denominator) + { + if (denominator == 0) + return ""; + string ans; + if ((numerator > 0 && denominator < 0) || (numerator < 0 && denominator > 0)) + ans = "-"; + long long num = abs(static_cast(numerator)); + long long den = abs(static_cast(denominator)); + long long quo = num / den; + long long rem = num % den; + + ans = ans + to_string(quo); + if (!rem) + return ans; + + ans += "."; + unordered_map u_m; + string s = ""; + int pos = 0; + while (rem) + { + if (u_m.find(rem) != u_m.end()) + { + s.insert(u_m[rem], "("); + s += ")"; + return ans + s; + } + u_m[rem] = pos++; + s += to_string((rem * 10) / den); + rem = (rem * 10) % den; + } + return ans + s; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/173.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/173.exercises/solution.md" index 3e229ebc2019e688a46a4fdb687e0f392fa74144..1e7b0621453a107ce7105cb075967d0a66f0d4c2 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/173.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/173.exercises/solution.md" @@ -61,6 +61,61 @@ bSTIterator.hasNext(); // 返回 False ## template ```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class BSTIterator +{ +public: + BSTIterator(TreeNode *root) + { + + for (; root != nullptr; root = root->left) + { + sti_.push(root); + } + } + + /** @return the next smallest number */ + int next() + { + + TreeNode *smallest = sti_.top(); + sti_.pop(); + int val = smallest->val; + + smallest = smallest->right; + for (; smallest != nullptr; smallest = smallest->left) + { + sti_.push(smallest); + } + return val; + } + + /** @return whether we have a next smallest number */ + bool hasNext() + { + return !sti_.empty(); + } + +private: + stack sti_; +}; + +/** + * Your BSTIterator object will be instantiated and called as such: + * BSTIterator* obj = new BSTIterator(root); + * int param_1 = obj->next(); + * bool param_2 = obj->hasNext(); + */ ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/177.exercises/solution.json" "b/data_source/exercises/\344\270\255\347\255\211/cpp/177.exercises/solution.json" deleted file mode 100644 index f1d0d72f01432f4e3bc3e4f46235aab8a594dcdf..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/177.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "423a11a1e52a42bfaf4c5664486742f3", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/177.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/177.exercises/solution.md" deleted file mode 100644 index 9d6c793ea78710bc5e45a8abb0bfad012fbcdbf7..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/177.exercises/solution.md" +++ /dev/null @@ -1,55 +0,0 @@ -# 第N高的薪水 - -

编写一个 SQL 查询,获取 Employee 表中第 高的薪水(Salary)。

- -
+----+--------+
-| Id | Salary |
-+----+--------+
-| 1  | 100    |
-| 2  | 200    |
-| 3  | 300    |
-+----+--------+
-
- -

例如上述 Employee 表,n = 2 时,应返回第二高的薪水 200。如果不存在第 高的薪水,那么查询应返回 null

- -
+------------------------+
-| getNthHighestSalary(2) |
-+------------------------+
-| 200                    |
-+------------------------+
-
- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/178.exercises/config.json" "b/data_source/exercises/\344\270\255\347\255\211/cpp/178.exercises/config.json" deleted file mode 100644 index 9d89959a4146faf3852db225a053b03e3afecc15..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/178.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-244566ecbe2e4102870b2c5226713404", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/178.exercises/solution.json" "b/data_source/exercises/\344\270\255\347\255\211/cpp/178.exercises/solution.json" deleted file mode 100644 index 54cb403131d4cf758b974cce2798ac49185f449a..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/178.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "50b3ae039f7b4139bb60e7acba009381", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/178.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/178.exercises/solution.md" deleted file mode 100644 index 8026754a5cc586032c77a2b2dee32de9a83ff49f..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/178.exercises/solution.md" +++ /dev/null @@ -1,67 +0,0 @@ -# 分数排名 - -

编写一个 SQL 查询来实现分数排名。

- -

如果两个分数相同,则两个分数排名(Rank)相同。请注意,平分后的下一个名次应该是下一个连续的整数值。换句话说,名次之间不应该有“间隔”。

- -
+----+-------+
-| Id | Score |
-+----+-------+
-| 1  | 3.50  |
-| 2  | 3.65  |
-| 3  | 4.00  |
-| 4  | 3.85  |
-| 5  | 4.00  |
-| 6  | 3.65  |
-+----+-------+
-
- -

例如,根据上述给定的 Scores 表,你的查询应该返回(按分数从高到低排列):

- -
+-------+------+
-| Score | Rank |
-+-------+------+
-| 4.00  | 1    |
-| 4.00  | 1    |
-| 3.85  | 2    |
-| 3.65  | 3    |
-| 3.65  | 3    |
-| 3.50  | 4    |
-+-------+------+
-
- -

重要提示:对于 MySQL 解决方案,如果要转义用作列名的保留字,可以在关键字之前和之后使用撇号。例如 `Rank`

- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/179.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/179.exercises/solution.md" index 0777f1f17df9afac2b4c81c9d02bec23974be92b..64b10c112350e317610f777cfb12a06200c9ea78 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/179.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/179.exercises/solution.md" @@ -46,7 +46,43 @@ ## template ```cpp - +#include +using namespace std; + +bool compare(string a, string b) +{ + string s1 = a + b; + string s2 = b + a; + return s1 > s2; +} + +class Solution +{ +public: + string largestNumber(vector &nums) + { + string res = ""; + int n = nums.size(); + vector tmp; + for (int i = 0; i < n; i++) + { + tmp.push_back(to_string(nums[i])); + } + sort(tmp.begin(), tmp.end(), compare); + for (int i = 0; i < tmp.size(); i++) + { + res += tmp[i]; + } + if ('0' == res[0]) + { + return "0"; + } + else + { + return res; + } + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/180.exercises/config.json" "b/data_source/exercises/\344\270\255\347\255\211/cpp/180.exercises/config.json" deleted file mode 100644 index 8c406b65055ad60b9a835abaf3e59aa63e583c0a..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/180.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-950af1c37af24bc284565acce90e2a66", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/180.exercises/solution.json" "b/data_source/exercises/\344\270\255\347\255\211/cpp/180.exercises/solution.json" deleted file mode 100644 index 5ed271e4e72b94fdda21a7d90c09fae1b0ec2907..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/180.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "244a40cf4e234089b4307d8c8350ba78", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/180.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/180.exercises/solution.md" deleted file mode 100644 index b36701d39d8a4260c495c2f83b773ab0c8d68a5d..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/180.exercises/solution.md" +++ /dev/null @@ -1,81 +0,0 @@ -# 连续出现的数字 - -

表:Logs

- -
-+-------------+---------+
-| Column Name | Type    |
-+-------------+---------+
-| id          | int     |
-| num         | varchar |
-+-------------+---------+
-id 是这个表的主键。
- -

 

- -

编写一个 SQL 查询,查找所有至少连续出现三次的数字。

- -

返回的结果表中的数据可以按 任意顺序 排列。

- -

 

- -

查询结果格式如下面的例子所示:

- -

 

- -
-Logs 表:
-+----+-----+
-| Id | Num |
-+----+-----+
-| 1  | 1   |
-| 2  | 1   |
-| 3  | 1   |
-| 4  | 2   |
-| 5  | 1   |
-| 6  | 2   |
-| 7  | 2   |
-+----+-----+
-
-Result 表:
-+-----------------+
-| ConsecutiveNums |
-+-----------------+
-| 1               |
-+-----------------+
-1 是唯一连续出现至少三次的数字。
-
- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/184.exercises/config.json" "b/data_source/exercises/\344\270\255\347\255\211/cpp/184.exercises/config.json" deleted file mode 100644 index c7c55fa91d61fe4e466397ec41c40110de0821d3..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/184.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-32c0f5429f2540e79a0e76bec87fb9bc", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/184.exercises/solution.json" "b/data_source/exercises/\344\270\255\347\255\211/cpp/184.exercises/solution.json" deleted file mode 100644 index f07c3b314ac69c2faa4a701b34d00bb49e0af0e2..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/184.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "5a1946c07e994950b3cf62e8cf16a1be", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/184.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/184.exercises/solution.md" deleted file mode 100644 index ff597c1026025edf12e1d393cf6a46273589bca3..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/184.exercises/solution.md" +++ /dev/null @@ -1,70 +0,0 @@ -# 部门工资最高的员工 - -

Employee 表包含所有员工信息,每个员工有其对应的 Id, salary 和 department Id。

- -
+----+-------+--------+--------------+
-| Id | Name  | Salary | DepartmentId |
-+----+-------+--------+--------------+
-| 1  | Joe   | 70000  | 1            |
-| 2  | Jim   | 90000  | 1            |
-| 3  | Henry | 80000  | 2            |
-| 4  | Sam   | 60000  | 2            |
-| 5  | Max   | 90000  | 1            |
-+----+-------+--------+--------------+
- -

Department 表包含公司所有部门的信息。

- -
+----+----------+
-| Id | Name     |
-+----+----------+
-| 1  | IT       |
-| 2  | Sales    |
-+----+----------+
- -

编写一个 SQL 查询,找出每个部门工资最高的员工。对于上述表,您的 SQL 查询应返回以下行(行的顺序无关紧要)。

- -
+------------+----------+--------+
-| Department | Employee | Salary |
-+------------+----------+--------+
-| IT         | Max      | 90000  |
-| IT         | Jim      | 90000  |
-| Sales      | Henry    | 80000  |
-+------------+----------+--------+
- -

解释:

- -

Max 和 Jim 在 IT 部门的工资都是最高的,Henry 在销售部的工资最高。

- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/186.exercises/config.json" "b/data_source/exercises/\344\270\255\347\255\211/cpp/186.exercises/config.json" deleted file mode 100644 index b9d7b1538a7a2ffa86f90004b979054293a99cfa..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/186.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-213eff6cd62c47e5b35ee411403b2a99", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/186.exercises/solution.json" "b/data_source/exercises/\344\270\255\347\255\211/cpp/186.exercises/solution.json" deleted file mode 100644 index 762cbcb98b9cd05d997c2efca514d1264f61450e..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/186.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "fbed10f1207f4794b8841fc0b9b94e32", - "author": "csdn.net", - "keywords": "双指针,字符串" -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/186.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/186.exercises/solution.md" deleted file mode 100644 index 8683cfbf9061ec635263c07ab92d0a0fc939c28d..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/186.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 翻转字符串里的单词 II - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/187.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/187.exercises/solution.md" index b64c60cf6a7ecf74904e5a32b84d7dcdefe66fab..6337f97aa0136f22cd2ff66a584e9704cd0154a0 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/187.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/187.exercises/solution.md" @@ -33,6 +33,39 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + vector findRepeatedDnaSequences(string s) + { + std::map word_map; + std::vector result; + for (int i = 0; i < s.length(); i++) + { + std::string word = s.substr(i, 10); + if (word_map.find(word) != word_map.end()) + { + word_map[word] += 1; + } + else + { + word_map[word] = 1; + } + } + std::map::iterator it; + for (it = word_map.begin(); it != word_map.end(); it++) + { + if (it->second > 1) + { + result.push_back(it->first); + } + } + return result; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/189.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/189.exercises/solution.md" index 4dcbf763545b84ad89dabeb25f8e061bdc620468..e014eb116a4414292ee17ec3f661b388925c5fde 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/189.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/189.exercises/solution.md" @@ -50,6 +50,31 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + void rotate(vector &nums, int k) + { + if (nums.empty()) + { + return; + } + int length = nums.size(); + k %= length; + while (k--) + { + int temp = nums[length - 1]; + for (int i = length - 1; i > 0; i--) + { + nums[i] = nums[i - 1]; + } + nums[0] = temp; + } + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/192.exercises/config.json" "b/data_source/exercises/\344\270\255\347\255\211/cpp/192.exercises/config.json" deleted file mode 100644 index 3c5c13969f12f159086b43ae64fe431254f1b035..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/192.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-b31dab96ba6446e093f8d41c799f136e", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/192.exercises/solution.json" "b/data_source/exercises/\344\270\255\347\255\211/cpp/192.exercises/solution.json" deleted file mode 100644 index c0a941aad9cded2de083fe428a1e8e87223186b8..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/192.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "2e404cdc85f148138041d73ed13ef5a3", - "author": "csdn.net", - "keywords": "位运算" -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/192.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/192.exercises/solution.md" deleted file mode 100644 index 47794756db4b2116acc80907a73d654849453cec..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/192.exercises/solution.md" +++ /dev/null @@ -1,68 +0,0 @@ -# 统计词频 - -

写一个 bash 脚本以统计一个文本文件 words.txt 中每个单词出现的频率。

- -

为了简单起见,你可以假设:

- -
    -
  • words.txt只包括小写字母和 ' ' 。
  • -
  • 每个单词只由小写字母组成。
  • -
  • 单词间由一个或多个空格字符分隔。
  • -
- -

示例:

- -

假设 words.txt 内容如下:

- -
the day is sunny the the
-the sunny is is
-
- -

你的脚本应当输出(以词频降序排列):

- -
the 4
-is 3
-sunny 2
-day 1
-
- -

说明:

- -
    -
  • 不要担心词频相同的单词的排序问题,每个单词出现的频率都是唯一的。
  • -
  • 你可以使用一行 Unix pipes 实现吗?
  • -
- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/194.exercises/config.json" "b/data_source/exercises/\344\270\255\347\255\211/cpp/194.exercises/config.json" deleted file mode 100644 index 4aa19cdf127abb08a464b51c5397f99895d13aec..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/194.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-73e6df452f8f4416bce3c1244c071318", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/194.exercises/solution.json" "b/data_source/exercises/\344\270\255\347\255\211/cpp/194.exercises/solution.json" deleted file mode 100644 index e896c661cded2322623e75c1cf3c81ac53f0d1a8..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/194.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "0be18e941d004a0b86d7c65ed0ef6539", - "author": "csdn.net", - "keywords": "shell" -} \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/194.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/194.exercises/solution.md" deleted file mode 100644 index 0bcda6f0513ccaab77a54091a245990b2c7eda1c..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/194.exercises/solution.md" +++ /dev/null @@ -1,58 +0,0 @@ -# 转置文件 - -

给定一个文件 file.txt,转置它的内容。

- -

你可以假设每行列数相同,并且每个字段由 ' ' 分隔。

- -

 

- -

示例:

- -

假设 file.txt 文件内容如下:

- -
-name age
-alice 21
-ryan 30
-
- -

应当输出:

- -
-name alice ryan
-age 21 30
-
- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/198.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/198.exercises/solution.md" index b3b5f7a46e6c7f2075fc3ad8eafcace9e8f3312c..8262deacb9d1162f19443057873d20181b735b62 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/198.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/198.exercises/solution.md" @@ -36,6 +36,30 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + int rob(vector &nums) + { + int n = nums.size(); + if (n == 0) + { + return 0; + } + + vector f(n + 1); + f[1] = nums[0]; + for (int i = 2; i <= n; ++i) + { + f[i] = max(f[i - 1], f[i - 2] + nums[i - 1]); + } + + return f[n]; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/199.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/199.exercises/solution.md" index 57793b7375c4ed58ef651074fb9393097ed75bc6..a98d76cd2d552bbc35274b947249ba099accf6fd 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/199.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/199.exercises/solution.md" @@ -40,7 +40,52 @@ ## template ```cpp - +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + vector rightSideView(TreeNode *root) + { + + vector ret; + queue queues[2]; + + if (root != NULL) + queues[0].push(root); + + int i = 0, j = 1, tmp; + TreeNode *p; + while (!queues[0].empty() || !queues[1].empty()) + { + while (!queues[i].empty()) + { + p = queues[i].front(); + queues[i].pop(); + if (p->left) + queues[j].push(p->left); + if (p->right) + queues[j].push(p->right); + tmp = p->val; + } + + ret.push_back(tmp); + i = (i + 1) % 2; + j = (j + 1) % 2; + } + + return ret; + } +}; ``` diff --git "a/data_source/exercises/\344\270\255\347\255\211/cpp/200.exercises/solution.md" "b/data_source/exercises/\344\270\255\347\255\211/cpp/200.exercises/solution.md" index d30da200c57ac0e81c5dcf215891a66d99d2562f..a745b86d2171fea693b63451b30e3fc4a9b7fe5f 100644 --- "a/data_source/exercises/\344\270\255\347\255\211/cpp/200.exercises/solution.md" +++ "b/data_source/exercises/\344\270\255\347\255\211/cpp/200.exercises/solution.md" @@ -47,7 +47,57 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + void DFS(vector> &mark, vector> &grid, int x, int y) + { + mark[x][y] = 1; + static const int dx[] = {-1, 1, 0, 0}; + static const int dy[] = {0, 0, -1, 1}; + for (int i = 0; i < 4; i++) + { + int newx = dx[i] + x; + int newy = dy[i] + y; + if (newx < 0 || newx >= mark.size() || newy < 0 || newy >= mark[newx].size()) + { + continue; + } + if (mark[newx][newy] == 0 && grid[newx][newy] == '1') + { + DFS(mark, grid, newx, newy); + } + } + } + int numIslands(vector> &grid) + { + int island_num = 0; + vector> mark; + for (int i = 0; i < grid.size(); i++) + { + mark.push_back(vector()); + for (int j = 0; j < grid[i].size(); j++) + { + mark[i].push_back(0); + } + } + for (int i = 0; i < grid.size(); i++) + { + for (int j = 0; j < grid[i].size(); j++) + { + if (mark[i][j] == 0 && grid[i][j] == '1') + { + DFS(mark, grid, i, j); + island_num++; + } + } + } + return island_num; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/115.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/115.exercises/solution.md" index 78ab5a86a2a0701abbde141781f2ae382ff9b872..c877942b2aebee548a1ceff40bc5c4a0b22ec298 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/115.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/115.exercises/solution.md" @@ -46,7 +46,29 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int numDistinct(string s, string t) + { + long dp[t.size() + 1][s.size() + 1]; + for (int i = 0; i <= s.size(); ++i) + dp[0][i] = 1; + for (int i = 1; i <= t.size(); ++i) + dp[i][0] = 0; + for (int i = 1; i <= t.size(); ++i) + { + for (int j = 1; j <= s.size(); ++j) + { + dp[i][j] = dp[i][j - 1] + (t[i - 1] == s[j - 1] ? dp[i - 1][j - 1] : 0); + } + } + return dp[t.size()][s.size()]; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/123.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/123.exercises/solution.md" index 53e0d56b570bd555cbd579b7d6404ac71d17ad78..e779d2fe09c233e70936fbb3e3fc3257ce5a680b 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/123.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/123.exercises/solution.md" @@ -54,7 +54,40 @@ ```cpp - +class Solution +{ +public: + int maxProfit(vector &prices) + { + int length = prices.size(); + if (length < 2) + { + return 0; + } + vector former(length, 0); + vector later(length, 0); + int curMin = prices[0]; + int curProfit = 0; + for (int i = 1; i < length; i++) + { + curProfit = max(curProfit, prices[i] - curMin); + curMin = min(curMin, prices[i]); + former[i] = curProfit; + } + int curMax = prices[length - 1]; + curProfit = 0; + for (int i = length - 2; i >= 0; i--) + { + curProfit = max(curProfit, curMax - prices[i]); + curMax = max(curMax, prices[i]); + later[i] = curProfit; + } + int maxProfit = 0; + for (int i = 0; i < length; i++) + maxProfit = max(maxProfit, former[i] + later[i]); + return maxProfit; + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/124.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/124.exercises/solution.md" index 9c093ae4c8a4b21b275aa4ecb4c8770bace3a949..6076c4909f0923b8e9be7f302e1feb106c908c15 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/124.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/124.exercises/solution.md" @@ -36,6 +36,69 @@ ## template ```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + int maxPathSum(TreeNode *root) + { + if (!root) + return 0; + vector ss; + unordered_map val; + ss.push_back(root); + int len = 1; + queue q{{root}}; + while (!q.empty()) + { + TreeNode *t = q.front(); + q.pop(); + cout << t->val << endl; + if (t->left) + { + len++; + q.push(t->left); + ss.push_back(t->left); + } + if (t->right) + { + len++; + q.push(t->right); + ss.push_back(t->right); + } + } + + int res = INT_MIN; + + while (len > 0) + { + TreeNode *node = ss[--len]; + int ps = node->val; + int s = ps; + + int ls = max(0, val[node->left]); + int rs = max(0, val[node->right]); + + ps += max(ls, rs); + val[node] = ps; + + s += ls + rs; + res = max(s, res); + } + + return res; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/126.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/126.exercises/solution.md" index 978d398632946113bcaaee31cee949f1cd972bfb..f3303bb6c8396e4549091115edc3bc6ceb65eda0 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/126.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/126.exercises/solution.md" @@ -52,7 +52,77 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + bool differ_one(string &s, string &t) + { + int n = 0; + for (int i = 0; i < s.size(); ++i) + if ((n += s[i] != t[i]) > 1) + return false; + return n == 1; + } + vector> fa; + vector tmp; + vector> ans; + void dfs(int index, vector &wordList) + { + if (fa[index].empty()) + { + reverse(tmp.begin(), tmp.end()); + ans.push_back(tmp); + reverse(tmp.begin(), tmp.end()); + } + for (auto &x : fa[index]) + { + tmp.push_back(wordList[x]); + dfs(x, wordList); + tmp.pop_back(); + } + } + vector> findLadders(string beginWord, string endWord, vector &wordList) + { + + int b = -1, e = -1, x; + for (int i = 0; i < wordList.size(); ++i) + { + if (wordList[i] == beginWord) + b = i; + if (wordList[i] == endWord) + e = i; + } + if (e == -1) + return ans; + if (b == -1) + wordList.push_back(beginWord), b = wordList.size() - 1; + queue que; + fa.assign(wordList.size(), vector()); + vector index(wordList.size(), 0); + que.push(b), index[b] = 1; + while (!que.empty()) + { + x = que.front(), que.pop(); + if (index[e] && index[x] >= index[e]) + break; + for (int i = 0; i < wordList.size(); ++i) + if ((index[i] == 0 || index[x] + 1 == index[i]) && differ_one(wordList[x], wordList[i])) + if (index[i] == 0) + index[i] = index[x] + 1, que.push(i), fa[i].push_back(x); + else + fa[i].push_back(x); + } + if (index[e] == 0) + return ans; + tmp.push_back(endWord); + dfs(e, wordList); + tmp.pop_back(); + return ans; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/127.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/127.exercises/solution.md" index cf2ac5e4d559e5e5aed930a5afa707f8c696f2cc..f4cb1a5b54badf098fbeb5993825a56e8fa28bf6 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/127.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/127.exercises/solution.md" @@ -45,6 +45,59 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + int ladderLength(string beginWord, string endWord, vector &wordList) + { + + unordered_set dict(wordList.begin(), wordList.end()); + if (dict.find(endWord) == dict.end()) + return 0; + + queue> q; + q.push(make_pair(beginWord, 1)); + + string tmp; + int step; + + while (!q.empty()) + { + auto p = q.front(); + + if (p.first == endWord) + return p.second; + tmp = p.first; + step = p.second; + q.pop(); + + char old_ch; + for (int i = 0; i < tmp.size(); ++i) + { + old_ch = tmp[i]; + + for (char c = 'a'; c <= 'z'; ++c) + { + + if (c == old_ch) + continue; + tmp[i] = c; + + if (dict.find(tmp) != dict.end()) + { + q.push(make_pair(tmp, step + 1)); + dict.erase(tmp); + } + } + tmp[i] = old_ch; + } + } + return 0; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/132.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/132.exercises/solution.md" index f65de6cf84bc280c08357271c0b064910cdf50c9..0f6086a2a122d728fb448773d31c347982eadb92 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/132.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/132.exercises/solution.md" @@ -45,7 +45,44 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int minCut(string s) + { + + const int N = s.size(); + if (N <= 1) + return 0; + + int i, j; + + bool isPalin[N][N]; + + fill_n(&isPalin[0][0], N * N, false); + + int minCuts[N + 1]; + for (i = 0; i <= N; ++i) + minCuts[i] = i - 1; + + for (j = 1; j < N; ++j) + { + for (i = j; i >= 0; --i) + { + + if ((s[i] == s[j]) && ((j - i < 2) || isPalin[i + 1][j - 1])) + { + isPalin[i][j] = true; + minCuts[j + 1] = min(minCuts[j + 1], 1 + minCuts[i]); + } + } + } + return minCuts[N]; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/135.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/135.exercises/solution.md" index 436ee2a02e2791368043e399709379ffea683501..e236f6a3400f6a729066ccaa099907bf3e166f9c 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/135.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/135.exercises/solution.md" @@ -33,7 +33,36 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int candy(vector &ratings) + { + int len = ratings.size(); + if (len < 2) + return len; + int candy[len + 1]; + candy[0] = 1; + for (int i = 1; i < len; i++) + { + if (ratings[i] > ratings[i - 1]) + candy[i] = candy[i - 1] + 1; + else + candy[i] = 1; + } + int ans = 0; + for (int i = len - 1; i > 0; i--) + { + if (candy[i] >= candy[i - 1] && ratings[i] < ratings[i - 1]) + candy[i - 1] = max(candy[i - 1], candy[i] + 1); + ans += candy[i]; + } + return ans + candy[0]; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/140.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/140.exercises/solution.md" index 9d36645c0335268c5e9e5d9f6b6933b692bd34d3..05bdff80431fd0056f8725387cc8070d48fa265a 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/140.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/140.exercises/solution.md" @@ -48,7 +48,57 @@ wordDict = ["cats", "dog", "sand", "and" ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + vector res; + unordered_set wordset; + unordered_set lenset; + vector wordBreak(string s, vector &wordDict) + { + for (const auto &w : wordDict) + { + wordset.insert(w); + lenset.insert(w.size()); + } + vector dp(s.size() + 1, 0); + dp[0] = 1; + for (int i = 1; i <= s.size(); ++i) + { + for (const auto &j : lenset) + { + if (i >= j && dp[i - j] && wordset.count(s.substr(i - j, j))) + dp[i] = 1; + } + } + + if (dp.back() == 0) + return res; + backtrack(dp, 0, s, ""); + return res; + } + + void backtrack(vector &dp, int idx, string &s, string tmp) + { + if (idx == s.size()) + { + tmp.pop_back(); + res.push_back(tmp); + return; + } + + for (int i = idx + 1; i < dp.size(); ++i) + { + if (dp[i] == 1 && wordset.count(s.substr(idx, i - idx))) + { + backtrack(dp, i, s, tmp + s.substr(idx, i - idx) + " "); + } + } + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/149.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/149.exercises/solution.md" index ce0383e8ca7dce4fc4805f020ed133567bfa898f..33c07367782b0e45734dfb1a815158104ed77aca 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/149.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/149.exercises/solution.md" @@ -33,6 +33,52 @@ ## template ```cpp +#include +using namespace std; + +struct Point +{ + int x; + int y; + Point() : x(0), y(0) {} + Point(int a, int b) : x(a), y(b) {} +}; + +class Solution +{ +public: + int maxPoints(vector &points) + { + int ans = 0; + for (int i = 0; i < points.size(); ++i) + { + map, int> m; + int p = 1; + for (int j = i + 1; j < points.size(); ++j) + { + if (points[i].x == points[j].x && (points[i].y == points[j].y)) + { + ++p; + continue; + } + int dx = points[j].x - points[i].x; + int dy = points[j].y - points[i].y; + int d = gcd(dx, dy); + ++m[{dx / d, dy / d}]; + } + ans = max(ans, p); + for (auto it = m.begin(); it != m.end(); ++it) + { + ans = max(ans, it->second + p); + } + } + return ans; + } + int gcd(int a, int b) + { + return (b == 0) ? a : gcd(b, a % b); + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/154.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/154.exercises/solution.md" index 6a567c85d0fb924ba37e0ee5afb90a699048e8f0..21c12edbba038cd87b8dd99155a25ca958a4cb29 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/154.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/154.exercises/solution.md" @@ -51,7 +51,29 @@ ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int findMin(vector &nums) + { + + int left = 0, right = nums.size() - 1; + while (left < right) + { + int mid = left + (right - left) / 2; + if (nums[mid] < nums[right]) + right = mid; + else if (nums[mid] > nums[right]) + left = mid + 1; + else if (nums[mid] == nums[right]) + right--; + } + return nums[right]; + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/158.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/158.exercises/config.json" deleted file mode 100644 index 3e2fc8ac16ab71fae9ac40d99694f1b5ea7d585f..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/158.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-49f201d5e01144c2a2f84579429f836c", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/158.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/158.exercises/solution.json" deleted file mode 100644 index 22715b227016cde282e3bf6ae12ffb9fa1fd3bd2..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/158.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "b2aa3694ca0242de826c70ff63223507", - "author": "csdn.net", - "keywords": "字符串,交互,模拟" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/158.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/158.exercises/solution.md" deleted file mode 100644 index 38d2c4c41950b3e9935a3a0698e97e19a927ea73..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/158.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 用 Read4 读取 N 个字符 II - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/164.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/164.exercises/solution.md" index c32bd86397ef5bfc96b45f6a53bc6d75909cb9b8..f5ddf1629a9ae743f23e1f7ec0d6aa1ebdeb40df 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/164.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/164.exercises/solution.md" @@ -27,7 +27,32 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int maximumGap(vector &nums) + { + set st(nums.begin(), nums.end()); + int res = 0, pre = INT_MIN; + for (auto iter = st.begin(); iter != st.end(); ++iter) + { + if (pre == INT_MIN) + { + pre = *iter; + continue; + } + else + { + res = max(res, *iter - pre); + pre = *iter; + } + } + return res; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/174.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/174.exercises/solution.md" index 3748ede121e14971b36f03250cdda58aa2b49f2e..6bd57595b872430b008b4d5d1251554a30e6c352 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/174.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/174.exercises/solution.md" @@ -62,7 +62,37 @@ table.dungeon, .dungeon th, .dungeon td { ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int calculateMinimumHP(vector> &dungeon) + { + int row = dungeon.size(); + int col = dungeon[0].size(); + int dp[row][col] = {0}; + dp[row - 1][col - 1] = max(1 - dungeon[row - 1][col - 1], 1); + for (int i = row - 2; i >= 0; i--) + { + dp[i][col - 1] = max(dp[i + 1][col - 1] - dungeon[i][col - 1], 1); + } + for (int i = col - 2; i >= 0; i--) + { + dp[row - 1][i] = max(dp[row - 1][i + 1] - dungeon[row - 1][i], 1); + } + for (int i = row - 2; i >= 0; i--) + { + for (int j = col - 2; j >= 0; j--) + { + dp[i][j] = max(min(dp[i + 1][j], dp[i][j + 1]) - dungeon[i][j], 1); + } + } + + return dp[0][0]; + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/185.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/185.exercises/config.json" deleted file mode 100644 index 8733000fcd5fa719e5d9aa53becb341e3b98d772..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/185.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-c8cd86452f7b48b1a1a34c7f9848eac0", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/185.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/185.exercises/solution.json" deleted file mode 100644 index 790a39090baca47748bcb98f7db80d6be9e5c61a..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/185.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "6d285794dd484abdb77537828c8b39d0", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/185.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/185.exercises/solution.md" deleted file mode 100644 index d0030969f17eaaa847a7c154843db2bf9d8b4599..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/185.exercises/solution.md" +++ /dev/null @@ -1,75 +0,0 @@ -# 部门工资前三高的所有员工 - -

Employee 表包含所有员工信息,每个员工有其对应的工号 Id,姓名 Name,工资 Salary 和部门编号 DepartmentId

- -
+----+-------+--------+--------------+
-| Id | Name  | Salary | DepartmentId |
-+----+-------+--------+--------------+
-| 1  | Joe   | 85000  | 1            |
-| 2  | Henry | 80000  | 2            |
-| 3  | Sam   | 60000  | 2            |
-| 4  | Max   | 90000  | 1            |
-| 5  | Janet | 69000  | 1            |
-| 6  | Randy | 85000  | 1            |
-| 7  | Will  | 70000  | 1            |
-+----+-------+--------+--------------+
- -

Department 表包含公司所有部门的信息。

- -
+----+----------+
-| Id | Name     |
-+----+----------+
-| 1  | IT       |
-| 2  | Sales    |
-+----+----------+
- -

编写一个 SQL 查询,找出每个部门获得前三高工资的所有员工。例如,根据上述给定的表,查询结果应返回:

- -
+------------+----------+--------+
-| Department | Employee | Salary |
-+------------+----------+--------+
-| IT         | Max      | 90000  |
-| IT         | Randy    | 85000  |
-| IT         | Joe      | 85000  |
-| IT         | Will     | 70000  |
-| Sales      | Henry    | 80000  |
-| Sales      | Sam      | 60000  |
-+------------+----------+--------+
- -

解释:

- -

IT 部门中,Max 获得了最高的工资,Randy 和 Joe 都拿到了第二高的工资,Will 的工资排第三。销售部门(Sales)只有两名员工,Henry 的工资最高,Sam 的工资排第二。

- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/188.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/188.exercises/solution.md" index 6853de0b578b7e56b9cc8aa5dcecf99b07b3f62e..9fb07084453735012ae91373c98730e9e29a63b7 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/188.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/188.exercises/solution.md" @@ -38,7 +38,40 @@ ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int maxProfit(int k, vector &prices) + { + const int len = prices.size(); + if (len <= 1 || k == 0) + return 0; + if (k > len / 2) + k = len / 2; + const int count = k; + int buy[count]; + int sell[count]; + for (int i = 0; i < count; ++i) + { + buy[i] = -prices[0]; + sell[i] = 0; + } + for (int i = 1; i < len; ++i) + { + buy[0] = max(buy[0], -prices[i]); + sell[0] = max(sell[0], buy[0] + prices[i]); + for (int j = count - 1; j > 0; --j) + { + buy[j] = max(buy[j], sell[j - 1] - prices[i]); + sell[j] = max(buy[j] + prices[i], sell[j]); + } + } + return sell[count - 1]; + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/212.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/212.exercises/solution.md" index 9782bf1e9672aceeff2fc95eaefdfd8a4f0288ce..3b47be88bd12a40f8f38fe890ec1994c4bd74918 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/212.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/212.exercises/solution.md" @@ -39,6 +39,95 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + struct Node + { + bool isflag = false; + Node *next[27] = {}; + }; + set res; + vector ans; + Node *root; + vector dirx{0, 0, 1, -1}; + vector diry{1, -1, 0, 0}; + bool flag; + + void createtree(vector &words) + { + root = new Node(); + + for (auto w : words) + { + Node *p = root; + for (int i = 0; i < w.length(); i++) + { + if (p->next[w[i] - 'a'] == NULL) + { + p->next[w[i] - 'a'] = new Node(); + } + p = p->next[w[i] - 'a']; + } + p->isflag = true; + } + } + void backtrack(vector> &board, vector> visited, int row, int col, Node *roott, string cur) + { + cur += board[row][col]; + roott = roott->next[board[row][col] - 'a']; + if (!roott) + return; + if (roott->isflag == true) + { + + res.insert(cur); + flag = true; + } + visited[row][col] = true; + + for (int i = 0; i < 4; i++) + { + + int nx = row + dirx[i]; + int ny = col + diry[i]; + if (nx < 0 || ny < 0 || nx >= board.size() || ny >= board[0].size()) + continue; + if (visited[nx][ny] == false) + { + backtrack(board, visited, nx, ny, roott, cur); + } + } + } + vector findWords(vector> &board, vector &words) + { + + if (board.size() == 0 || words.size() == 0) + return ans; + createtree(words); + + for (int i = 0; i < board.size(); i++) + { + for (int j = 0; j < board[i].size(); j++) + { + Node *p = root; + flag = false; + if (p->next[board[i][j] - 'a']) + { + vector> visited{board.size(), vector(board[0].size(), false)}; + backtrack(board, visited, i, j, p, ""); + } + } + } + set::iterator it; + for (it = res.begin(); it != res.end(); it++) + ans.push_back(*it); + return ans; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/214.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/214.exercises/solution.md" index 0507aa022966af557bb948167093110f4be6ff4b..6edbda8461fd2a4615bd8ed30f57f9e0246b8b73 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/214.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/214.exercises/solution.md" @@ -31,6 +31,58 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + string shortestPalindrome(string s) + { + + string rev(s); + reverse(rev.begin(), rev.end()); + ; + string combine = s + "#" + rev; + + vector lps(combine.length(), 0); + int remove = getLPS(combine, lps); + + string prepend = rev.substr(0, rev.length() - remove); + return prepend + s; + } + + int getLPS(string s, vector &lps) + { + + int j = 0, i = 1; + + while (i < s.length()) + { + + if (s[i] == s[j]) + { + lps[i] = j + 1; + i++; + j++; + } + else + { + + if (j != 0) + { + j = lps[j - 1]; + } + else + { + lps[i] = 0; + i++; + } + } + } + return lps[lps.size() - 1]; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/218.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/218.exercises/solution.md" index b0975d8a57d9fb7adeb2afaaf9060dae365ac7dc..c3286e1ca5ae14e92bfa8df3219921b3b58c6377 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/218.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/218.exercises/solution.md" @@ -47,7 +47,40 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + vector> getSkyline(vector> &buildings) + { + vector> h, res; + multiset m; + int pre = 0, cur = 0; + for (auto &a : buildings) + { + h.push_back({a[0], -a[2]}); + h.push_back({a[1], a[2]}); + } + sort(h.begin(), h.end()); + m.insert(0); + for (auto &a : h) + { + if (a.second < 0) + m.insert(-a.second); + else + m.erase(m.find(a.second)); + cur = *m.rbegin(); + if (cur != pre) + { + res.push_back({a.first, cur}); + pre = cur; + } + } + return res; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/224.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/224.exercises/solution.md" index 0403780908231b151ff9d733cd64a407e787b333..8ffe591ae033b737f6f759580edfa871051c355f 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/224.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/224.exercises/solution.md" @@ -39,7 +39,86 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int calculate(string s) + { + stack myStack; + stack myOperator; + int i; + for (i = 0; i < s.length(); i++) + { + while (i < s.length() && s[i] == ' ') + i++; + if (i == s.length()) + break; + if (s[i] == '+' || s[i] == '-' || s[i] == '(') + myOperator.push(s[i]); + else if (s[i] == ')') + { + while (myOperator.top() != '(') + { + int element1 = myStack.top(); + myStack.pop(); + int element2 = myStack.top(); + myStack.pop(); + char op = myOperator.top(); + myOperator.pop(); + if (op == '+') + myStack.push(element1 + element2); + else if (op == '-') + myStack.push(element2 - element1); + } + if (!myOperator.empty()) + myOperator.pop(); + while (!myOperator.empty() && (myOperator.top() != '(')) + { + int element1 = myStack.top(); + myStack.pop(); + int element2 = myStack.top(); + myStack.pop(); + char op = myOperator.top(); + myOperator.pop(); + if (op == '+') + myStack.push(element1 + element2); + else if (op == '-') + myStack.push(element2 - element1); + } + } + else + { + + long long int number = 0; + int j = i; + while (j < s.length() && (s[j] - '0' <= 9) && (s[j] - '0' >= 0)) + { + number = number * 10 + (s[j] - '0'); + j++; + } + i = j - 1; + myStack.push(number); + while (!myOperator.empty() && (myOperator.top() != '(')) + { + int element1 = myStack.top(); + myStack.pop(); + int element2 = myStack.top(); + myStack.pop(); + char op = myOperator.top(); + myOperator.pop(); + if (op == '+') + myStack.push(element1 + element2); + else if (op == '-') + myStack.push(element2 - element1); + } + } + } + return myStack.top(); + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/233.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/233.exercises/solution.md" index 18d47db320434869aca0a940dc0d31efcbfab847..554a174fb02f8bf6d12685006267e18400506f1c 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/233.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/233.exercises/solution.md" @@ -30,6 +30,25 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + int countDigitOne(int n) + { + int cnt = 0; + for (long int i = 1; i <= n; i *= 10) + { + int a = n / i, b = n % i; + cnt += (a + 8) / 10 * i + (a % 10 == 1) * (b + 1); + if (i == 1000000000) + break; + } + return cnt; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/239.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/239.exercises/solution.md" index dcd2ec60aa904ee603e3bf0e95bb55714fd999ad..17c01ca76bfff0c62fe66bf9108557941e059d42 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/239.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/239.exercises/solution.md" @@ -63,6 +63,35 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + vector maxSlidingWindow(vector &nums, int k) + { + vector ans; + int n = nums.size(); + if (n == 0 || k > n) + return ans; + deque que; + for (int i = 0; i < n; i++) + { + if (!que.empty()) + { + if (i >= que.front() + k) + que.pop_front(); + while (!que.empty() && nums[i] >= nums[que.back()]) + que.pop_back(); + } + que.push_back(i); + if (i + 1 >= k) + ans.push_back(nums[que.front()]); + } + return ans; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/248.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/248.exercises/config.json" deleted file mode 100644 index d7b825b80d20e8efecb3cbeba9e4fd5c1c63c797..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/248.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-628335996f8841539f799aa4e7a9f566", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/248.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/248.exercises/solution.json" deleted file mode 100644 index fea26ec3712cd74d6310948fd18910901c724666..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/248.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "fe40de84da824faab29335d99ba2e657", - "author": "csdn.net", - "keywords": "递归,数组,字符串" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/248.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/248.exercises/solution.md" deleted file mode 100644 index 22dabea64bd2d8feb098d924f523eac3844b5aae..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/248.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 中心对称数 III - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/262.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/262.exercises/config.json" deleted file mode 100644 index 834c7b0c51e7f1143606305048c15a32d76c7960..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/262.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-074590fe6aba43c38069b88da114d531", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/262.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/262.exercises/solution.json" deleted file mode 100644 index ecc40bdaadde00669f3f87eafd8d057db4463e41..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/262.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "60abd10c9b734a86b65145f3247c8099", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/262.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/262.exercises/solution.md" deleted file mode 100644 index 7d04382f4ed87c9ce982d26863dc5c3619d68682..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/262.exercises/solution.md" +++ /dev/null @@ -1,146 +0,0 @@ -# 行程和用户 - -表:Trips -
-
-
-+-------------+----------+
-| Column Name | Type     |
-+-------------+----------+
-| Id          | int      |
-| Client_Id   | int      |
-| Driver_Id   | int      |
-| City_Id     | int      |
-| Status      | enum     |
-| Request_at  | date     |     
-+-------------+----------+
-Id 是这张表的主键。
-这张表中存所有出租车的行程信息。每段行程有唯一 Id ,其中 Client_Id 和 Driver_Id 是 Users 表中 Users_Id 的外键。
-Status 是一个表示行程状态的枚举类型,枚举成员为(‘completed’, ‘cancelled_by_driver’, ‘cancelled_by_client’) 。
-
- -

 

- -
-
-

表:Users

-
-
- -
-+-------------+----------+
-| Column Name | Type     |
-+-------------+----------+
-| Users_Id    | int      |
-| Banned      | enum     |
-| Role        | enum     |
-+-------------+----------+
-Users_Id 是这张表的主键。
-这张表中存所有用户,每个用户都有一个唯一的 Users_Id ,Role 是一个表示用户身份的枚举类型,枚举成员为 (‘client’, ‘driver’, ‘partner’) 。
-Banned 是一个表示用户是否被禁止的枚举类型,枚举成员为 (‘Yes’, ‘No’) 。
-
- -

 

- -

写一段 SQL 语句查出 "2013-10-01" 至 "2013-10-03" 期间非禁止用户(乘客和司机都必须未被禁止)的取消率。非禁止用户即 Banned 为 No 的用户,禁止用户即 Banned 为 Yes 的用户。

- -

取消率 的计算方式如下:(被司机或乘客取消的非禁止用户生成的订单数量) / (非禁止用户生成的订单总数)。

- -

返回结果表中的数据可以按任意顺序组织。其中取消率 Cancellation Rate 需要四舍五入保留 两位小数

- -

 

- -

查询结果格式如下例所示:

- -
-Trips 表:
-+----+-----------+-----------+---------+---------------------+------------+
-| Id | Client_Id | Driver_Id | City_Id | Status              | Request_at |
-+----+-----------+-----------+---------+---------------------+------------+
-| 1  | 1         | 10        | 1       | completed           | 2013-10-01 |
-| 2  | 2         | 11        | 1       | cancelled_by_driver | 2013-10-01 |
-| 3  | 3         | 12        | 6       | completed           | 2013-10-01 |
-| 4  | 4         | 13        | 6       | cancelled_by_client | 2013-10-01 |
-| 5  | 1         | 10        | 1       | completed           | 2013-10-02 |
-| 6  | 2         | 11        | 6       | completed           | 2013-10-02 |
-| 7  | 3         | 12        | 6       | completed           | 2013-10-02 |
-| 8  | 2         | 12        | 12      | completed           | 2013-10-03 |
-| 9  | 3         | 10        | 12      | completed           | 2013-10-03 |
-| 10 | 4         | 13        | 12      | cancelled_by_driver | 2013-10-03 |
-+----+-----------+-----------+---------+---------------------+------------+
-
-Users 表:
-+----------+--------+--------+
-| Users_Id | Banned | Role   |
-+----------+--------+--------+
-| 1        | No     | client |
-| 2        | Yes    | client |
-| 3        | No     | client |
-| 4        | No     | client |
-| 10       | No     | driver |
-| 11       | No     | driver |
-| 12       | No     | driver |
-| 13       | No     | driver |
-+----------+--------+--------+
-
-Result 表:
-+------------+-------------------+
-| Day        | Cancellation Rate |
-+------------+-------------------+
-| 2013-10-01 | 0.33              |
-| 2013-10-02 | 0.00              |
-| 2013-10-03 | 0.50              |
-+------------+-------------------+
-
-2013-10-01:
-  - 共有 4 条请求,其中 2 条取消。
-  - 然而,Id=2 的请求是由禁止用户(User_Id=2)发出的,所以计算时应当忽略它。
-  - 因此,总共有 3 条非禁止请求参与计算,其中 1 条取消。
-  - 取消率为 (1 / 3) = 0.33
-2013-10-02:
-  - 共有 3 条请求,其中 0 条取消。
-  - 然而,Id=6 的请求是由禁止用户发出的,所以计算时应当忽略它。
-  - 因此,总共有 2 条非禁止请求参与计算,其中 0 条取消。
-  - 取消率为 (0 / 2) = 0.00
-2013-10-03:
-  - 共有 3 条请求,其中 1 条取消。
-  - 然而,Id=8 的请求是由禁止用户发出的,所以计算时应当忽略它。
-  - 因此,总共有 2 条非禁止请求参与计算,其中 1 条取消。
-  - 取消率为 (1 / 2) = 0.50
-
-
-
- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/265.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/265.exercises/config.json" deleted file mode 100644 index bf591ebff72d19b0114c3f06970e817b74cb4402..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/265.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-9f00778149124d1fb4fe252c56cb752d", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/265.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/265.exercises/solution.json" deleted file mode 100644 index 1fe13d64b904db81dca82acdb375b567239b1bf0..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/265.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "fe307b22d8504239a26cd327d212c4ca", - "author": "csdn.net", - "keywords": "数组,动态规划" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/265.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/265.exercises/solution.md" deleted file mode 100644 index 98dcd19a74af047e88876fefb025e687e7b41658..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/265.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 粉刷房子 II - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/269.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/269.exercises/config.json" deleted file mode 100644 index 1e476824fb314ca47676ca988e1d02a7064cfb6b..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/269.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-aa039e08044a46348cc5f4e989a03b85", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/269.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/269.exercises/solution.md" deleted file mode 100644 index 052f43f58c85cd0cc40907dc3a94e73cd77e380e..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/269.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 火星词典 - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/272.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/272.exercises/config.json" deleted file mode 100644 index 6d7edc10521e460e51643fc2356b8d2e8f356851..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/272.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-633c198f85454eefa51290efdf1fed95", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/272.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/272.exercises/solution.json" deleted file mode 100644 index 25f2216159b1b66cd1ed277e2699bdc4becf66e8..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/272.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "291feb913dc349d2853e7eaeb74c6440", - "author": "csdn.net", - "keywords": "栈,树,深度优先搜索,二叉搜索树,双指针,二叉树,堆(优先队列)" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/272.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/272.exercises/solution.md" deleted file mode 100644 index d90c90825975622d1538792efd707f416f7b9fe0..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/272.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 最接近的二叉搜索树值 II - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/273.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/273.exercises/solution.md" index b6e5aba4edcad1278f7aa63be077ddab54163ae9..3db9507acfec8f01305cf753b3ee150586c1de08 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/273.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/273.exercises/solution.md" @@ -44,7 +44,55 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + const int Mod[3] = {1000000000, 1000000, 1000}; + string H[3] = {"Billion", "Million", "Thousand"}, + M[8] = {"Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"}, + L[20] = {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", + "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"}; + void update(string &ans) + { + ans += ans == "" ? "" : " "; + } + string numberToWords2(int num) + { + if (num < 20) + return L[num]; + string ans; + if (num >= 100) + ans += L[num / 100] + " Hundred", num %= 100; + if (num == 0) + return ans; + else if (num < 20) + update(ans), ans += L[num]; + else + { + update(ans), ans += M[num / 10 - 2], num %= 10; + if (num == 0) + return ans; + else + update(ans), ans += L[num]; + } + return ans; + } + string numberToWords(int num) + { + if (num < 20) + return L[num]; + string ans; + for (int i = 0; i < 3; ++i) + if (num >= Mod[i]) + update(ans), ans += numberToWords2(num / Mod[i]) + " " + H[i], num %= Mod[i]; + if (num) + update(ans), ans += numberToWords2(num); + return ans; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/282.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/282.exercises/solution.md" index c6f5a70cf6266b0b57772c08e17f40791cac6824..6dde1b7190ef56c282302f93e7bb3af51aa6f9eb 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/282.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/282.exercises/solution.md" @@ -50,7 +50,40 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + vector addOperators(string num, int target) + { + vector res; + addOperatorsDFS(num, target, 0, 0, "", res); + return res; + } + + void addOperatorsDFS(string num, int target, long long diff, long long curNum, string out, vector &res) + { + if (num.size() == 0 && curNum == target) + res.push_back(out); + for (int i = 1; i <= num.size(); ++i) + { + string cur = num.substr(0, i); + if (cur.size() > 1 && cur[0] == '0') + return; + string next = num.substr(i); + if (out.size() > 0) + { + addOperatorsDFS(next, target, stoll(cur), curNum + stoll(cur), out + "+" + cur, res); + addOperatorsDFS(next, target, -stoll(cur), curNum - stoll(cur), out + "-" + cur, res); + addOperatorsDFS(next, target, diff * stoll(cur), (curNum - diff) + diff * stoll(cur), out + "*" + cur, res); + } + else + addOperatorsDFS(next, target, stoll(cur), stoll(cur), cur, res); + } + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/295.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/295.exercises/solution.md" index b8c4699278bb6c3473c1cd4c8624ba7701044fa3..98f702180ae3b5b72d2afcddd1bf017bc6512335 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/295.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/295.exercises/solution.md" @@ -34,7 +34,40 @@ findMedian() -> 2 ## template ```cpp - +#include +using namespace std; + +class MedianFinder +{ +public: + /** initialize your data structure here. */ + MedianFinder() + { + } + + void addNum(int num) + { + auto it = upper_bound(nums.begin(), nums.end(), num); + nums.insert(it, num); + } + + double findMedian() + { + int n = nums.size(); + if (n % 2 == 0) + return 1.0 * (nums[n / 2 - 1] + nums[n / 2]) / 2; + else + return nums[n / 2]; + } + vector nums; +}; + +/** + * Your MedianFinder object will be instantiated and called as such: + * MedianFinder obj = new MedianFinder(); + * obj.addNum(num); + * double param_2 = obj.findMedian(); + */ ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/296.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/296.exercises/config.json" deleted file mode 100644 index b04a6b78ef82b87c8010d2c8bfa6b1e11f2bf06b..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/296.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-d3dc18ee39d44a61aafd21f2fcba7193", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/296.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/296.exercises/solution.json" deleted file mode 100644 index 731e547af5b0fe2ccc6b48b4839de96b221e3354..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/296.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "512fdf0148974c72a98c33435828fc09", - "author": "csdn.net", - "keywords": "数组,数学,矩阵,排序" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/296.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/296.exercises/solution.md" deleted file mode 100644 index aed848624627feea3e3080f17e8d26982b9d93c3..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/296.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 最佳的碰头地点 - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/297.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/297.exercises/solution.md" index f170011029a09ef253df60f695b1e6e3531a2502..36524d2a938994aa996430b97de2061c60c216ea 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/297.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/297.exercises/solution.md" @@ -49,7 +49,50 @@ ## template ```cpp - +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Codec +{ +public: + string serialize(TreeNode *root) + { + if (!root) + return "#_"; + return to_string(root->val) + "_" + serialize(root->left) + serialize(root->right); + } + + TreeNode *deserialize(string data) + { + cout << data << endl; + queue q; + stringstream ss(data); + string s; + while (getline(ss, s, '_')) + q.push(s); + return help(q); + } + + TreeNode *help(queue &q) + { + auto cur = q.front(); + q.pop(); + if (cur == "#") + return NULL; + auto root = new TreeNode(stoi(cur)); + root->left = help(q); + root->right = help(q); + return root; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/301.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/301.exercises/solution.md" index d45b539f06fb9d627bfde9038dccad0f8552f772..1b23a82e90c5cc2bf1f2016e14b674cb564c82de 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/301.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/301.exercises/solution.md" @@ -41,6 +41,53 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + vector removeInvalidParentheses(string s) + { + vector ans; + rm(move(s), ans, {'(', ')'}, 0, 0); + if (ans.empty()) + return {""}; + return ans; + } + + void rm(string s, vector &ans, vector brackets, int sea_i, int del_i) + { + int sta = 0; + for (int i = sea_i; i < s.size(); i++) + { + if (s[i] == brackets[0]) + sta++; + else if (s[i] == brackets[1]) + { + sta--; + if (sta < 0) + { + for (int j = del_i; j <= i; j++) + { + if (s[j] == brackets[1] && (j == del_i || s[j - 1] != brackets[1])) + { + string new_s = s.substr(0, j) + s.substr(j + 1); + rm(move(new_s), ans, brackets, i, j); + } + } + return; + } + } + } + + reverse(s.begin(), s.end()); + if (brackets[0] == '(') + rm(move(s), ans, {brackets[1], brackets[0]}, 0, 0); + else + ans.push_back(move(s)); + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/302.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/302.exercises/config.json" deleted file mode 100644 index 686e3fefb1833dcb0719c97dc5ec703de77363a3..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/302.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-ee6d28c728da446281e36cce4f00d185", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/302.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/302.exercises/solution.json" deleted file mode 100644 index 174d0fc6caaabfb747a28ce311681aa057bf0fa1..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/302.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "8e86497cc7714b4b97025466d96b6fc8", - "author": "csdn.net", - "keywords": "深度优先搜索,广度优先搜索,数组,二分查找,矩阵" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/302.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/302.exercises/solution.md" deleted file mode 100644 index 5dab111bb64b60ad31f7d45bcb0982022943a9e1..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/302.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 包含全部黑色像素的最小矩形 - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/305.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/305.exercises/config.json" deleted file mode 100644 index 4156d6dbacd210e1eac0ab0997e386bce4d17ef4..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/305.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-a0b6ba89feb84ddab4f88213e97b2db1", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/305.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/305.exercises/solution.json" deleted file mode 100644 index 7799a8106ac26da6f8497a49e4fb7745c52d7d7e..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/305.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "f8dd07bb72784c4d913949a13a6e2be0", - "author": "csdn.net", - "keywords": "并查集,数组" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/305.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/305.exercises/solution.md" deleted file mode 100644 index cecc6b36f278cd04e890596ec0ba2b313b566925..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/305.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 岛屿数量 II - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/308.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/308.exercises/config.json" deleted file mode 100644 index a0533bc57e63446785ab14a62441851b0ab625c4..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/308.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-d2f2b1a20e0948aaac5e162103913570", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/308.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/308.exercises/solution.json" deleted file mode 100644 index f9b423badf30bb7076bf698b2ac014e255a899d3..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/308.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "12e2d537f6664ed8a3afbdbb1fb1c620", - "author": "csdn.net", - "keywords": "设计,树状数组,线段树,数组,矩阵" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/308.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/308.exercises/solution.md" deleted file mode 100644 index c044e0d7ce1759e696913380eb4007c987907817..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/308.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 二维区域和检索 - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/312.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/312.exercises/solution.md" index 3ba40860fbccd2e89dcae13091452a2b1379b54d..c81be943483f3f20f344a5e92ccb76873a7da02e 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/312.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/312.exercises/solution.md" @@ -37,7 +37,33 @@ coins = 3*1*5 + 3*5*8 + 1*3*8 + 1*8*1 = 167 ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int maxCoins(vector &nums) + { + vector dpnums(nums.size() + 2, 1); + for (int i = 0, j = 1; i < nums.size(); i++, j++) + dpnums[j] = nums[i]; + + vector> coins(dpnums.size(), vector(dpnums.size(), 0)); + for (int i = 2; i < dpnums.size(); i++) + { + for (int j = 0; j + i < dpnums.size(); j++) + { + for (int k = j + 1; k < j + i; k++) + { + coins[j][j + i] = max(coins[j][j + i], coins[j][k] + coins[k][j + i] + + dpnums[j] * dpnums[k] * dpnums[j + i]); + } + } + } + return coins[0][dpnums.size() - 1]; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/315.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/315.exercises/solution.md" index 695bd952b3f31585a8cf32fd014f84ef63b7e04f..463e1392cd551c1de6bf2c54df08c04ebd7325b1 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/315.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/315.exercises/solution.md" @@ -43,6 +43,73 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + struct BSTNode + { + int val; + int count; + BSTNode *left; + BSTNode *right; + BSTNode(int x) : val(x), left(NULL), right(NULL), count(0) {} + }; + + void BST_insert(BSTNode *node, BSTNode *insert_node, int &count_small) + { + if (insert_node->val <= node->val) + { + node->count++; + if (node->left) + { + BST_insert(node->left, insert_node, count_small); + } + else + { + node->left = insert_node; + } + } + else + { + count_small += node->count + 1; + if (node->right) + { + BST_insert(node->right, insert_node, count_small); + } + else + { + node->right = insert_node; + } + } + } + + vector countSmaller(vector &nums) + { + vector result; + vector node_vec; + vector count; + for (int i = nums.size() - 1; i >= 0; i--) + { + node_vec.push_back(new BSTNode(nums[i])); + } + count.push_back(0); + for (int i = 1; i < node_vec.size(); i++) + { + int count_small = 0; + BST_insert(node_vec[0], node_vec[i], count_small); + count.push_back(count_small); + } + for (int i = node_vec.size() - 1; i >= 0; i--) + { + delete node_vec[i]; + result.push_back(count[i]); + } + return result; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/317.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/317.exercises/config.json" deleted file mode 100644 index 2d78fc724ec0f830c999d7a00f4ef77cd3ff6992..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/317.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-e9efbb273d38435e9dc8f37360a068b5", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/317.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/317.exercises/solution.json" deleted file mode 100644 index 8a40c7794db9e9bb0e88f10ec40cc0f689590bd6..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/317.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "3a8c7a4666fd418197154af3534f1827", - "author": "csdn.net", - "keywords": "广度优先搜索,数组,矩阵" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/317.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/317.exercises/solution.md" deleted file mode 100644 index eba9590472b2f97a35ef95892847be682ad4abd5..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/317.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 离建筑物最近的距离 - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/321.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/321.exercises/solution.md" index 4b64f60d59a0c171997364420f5a684080f8807e..dec6783eda80d5824c412d2284d00284b0f07e8f 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/321.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/321.exercises/solution.md" @@ -37,7 +37,64 @@ k = 3 ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + vector maxNumber(vector &nums1, vector &nums2, int k) + { + vector ans; + const int n1 = nums1.size(); + const int n2 = nums2.size(); + for (int k1 = 0; k1 <= k; ++k1) + { + const int k2 = k - k1; + if (k1 > n1 || k2 > n2) + { + continue; + } + ans = max(ans, maxNumber(maxNumber(nums1, k1), maxNumber(nums2, k2))); + } + return ans; + } + +private: + vector maxNumber(const vector &nums, const int k) + { + if (k == 0) + { + return {}; + } + vector ans; + int to_pop = nums.size() - k; + for (const int num : nums) + { + while (!ans.empty() && num > ans.back() && to_pop-- > 0) + { + ans.pop_back(); + } + ans.push_back(num); + } + ans.resize(k); + return ans; + } + + vector maxNumber(const vector &nums1, const vector &nums2) + { + vector ans; + auto s1 = nums1.cbegin(); + auto e1 = nums1.cend(); + auto s2 = nums2.cbegin(); + auto e2 = nums2.cend(); + while (s1 != e1 || s2 != e2) + { + ans.push_back(lexicographical_compare(s1, e1, s2, e2) ? *s2++ : *s1++); + } + return ans; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/327.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/327.exercises/solution.md" index 68a0e3d8f60a843c2d667f0fdfad23f51752a588..0a0be9a077d63062df9b7c7127babb0bf6aa1aa1 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/327.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/327.exercises/solution.md" @@ -35,6 +35,31 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + int countRangeSum(vector &nums, int lower, int upper) + { + int n = nums.size(); + long presum = 0; + + multiset S; + S.insert(0); + int ret = 0; + + for (int i = 0; i < n; i++) + { + presum += nums[i]; + + ret += distance(S.lower_bound(presum - upper), S.upper_bound(presum - lower)); + S.insert(presum); + } + return ret; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/329.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/329.exercises/solution.md" index 3aab71ad98036c7ce20b77a64463073d83d1d6cf..88cb6e09d079e8d14dbd0a5c04dba13686f61ff3 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/329.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/329.exercises/solution.md" @@ -43,6 +43,56 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + static constexpr int dirs[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; + int m, n; + int longestIncreasingPath(vector> &matrix) + { + if (matrix.size() == 0 || matrix[0].size() == 0) + { + return 0; + } + m = matrix.size(); + n = matrix[0].size(); + int res = 0; + auto memo = vector>(m, vector(n, 0)); + for (int i = 0; i < m; ++i) + { + for (int j = 0; j < n; ++j) + { + if (memo[i][j]) + res = max(res, memo[i][j]); + else + res = max(res, dfs(i, j, matrix, memo)); + } + } + return res; + } + + int dfs(int i, int j, vector> &matrix, vector> &memo) + { + int temp = 1; + for (int k = 0; k < 4; ++k) + { + int x = i + dirs[k][0]; + int y = j + dirs[k][1]; + if ((x >= 0) && (x < m) && (y >= 0) && (y < n) && (matrix[i][j] < matrix[x][y])) + { + if (memo[x][y]) + temp = max(temp, memo[x][y] + 1); + else + temp = max(temp, dfs(x, y, matrix, memo) + 1); + } + } + memo[i][j] = temp; + return temp; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/330.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/330.exercises/solution.md" index c7f2ee93b18f88038f3c88a21f50170f7c3cca61..f549a29f2ee60b5e9d2e0975fc5d36b1eea9b3bb 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/330.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/330.exercises/solution.md" @@ -29,6 +29,35 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + int minPatches(vector &nums, int n) + { + long max_sum = 0; + int m = nums.size(); + int cnt = 0; + for (long i = 1, pos = 0; i <= n;) + { + + if (pos >= m || i < nums[pos]) + { + cnt++; + max_sum += i; + } + else + { + max_sum += nums[pos]; + pos++; + } + i = max_sum + 1; + } + return cnt; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/335.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/335.exercises/solution.md" index cf5a2670fce7172ae68a248fe67757f0183ea4ab..6d6563304c69ad070882f4cdf2eb613d9b41c96f 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/335.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/335.exercises/solution.md" @@ -41,7 +41,36 @@ ## template ```cpp +#include +using namespace std; +class Solution +{ +public: + bool isSelfCrossing(vector &distance) + { + int all_step = distance.size(), current_step = 0; + + if (all_step < 4) + return false; + + current_step = 2; + + while (current_step < all_step && distance[current_step] > distance[current_step - 2]) + current_step++; + if (current_step == all_step) + return false; + + if (distance[current_step] >= distance[current_step - 2] - (current_step > 3 ? distance[current_step - 4] : 0)) + distance[current_step - 1] -= current_step > 2 ? distance[current_step - 3] : 0; + current_step++; + + while (current_step < all_step && distance[current_step] < distance[current_step - 2]) + current_step++; + + return current_step != all_step; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/336.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/336.exercises/solution.md" index 6a29e21ddeff4d4f6de3ae26cb65ca6f4b4a4fff..5918455c4ee4cb704b14dc5dc931e18717d59d7b 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/336.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/336.exercises/solution.md" @@ -40,6 +40,57 @@ ```cpp +#include +using namespace std; + +class Solution +{ +public: + vector> palindromePairs(vector &words) + { + vector> res; + unordered_map m; + set s; + for (int i = 0; i < words.size(); ++i) + { + m[words[i]] = i; + s.insert(words[i].size()); + } + for (int i = 0; i < words.size(); ++i) + { + string t = words[i]; + int len = t.size(); + reverse(t.begin(), t.end()); + if (m.count(t) && m[t] != i) + { + res.push_back({i, m[t]}); + } + auto a = s.find(len); + for (auto it = s.begin(); it != a; ++it) + { + int d = *it; + if (isValid(t, 0, len - d - 1) && m.count(t.substr(len - d))) + { + res.push_back({i, m[t.substr(len - d)]}); + } + if (isValid(t, d, len - 1) && m.count(t.substr(0, d))) + { + res.push_back({m[t.substr(0, d)], i}); + } + } + } + return res; + } + bool isValid(string t, int left, int right) + { + while (left < right) + { + if (t[left++] != t[right--]) + return false; + } + return true; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/352.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/352.exercises/solution.md" index e7d383cd452a57d584e4f5210cc203f2bbd78a8e..c821f1a48eed3f4003016c9f4148132f5e7d097b 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/352.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/352.exercises/solution.md" @@ -56,6 +56,91 @@ summaryRanges.getIntervals(); // 返回 [[1, 3], [6, 7]] ## template ```cpp +#include +using namespace std; + +class SummaryRanges +{ +public: + vector> ans; + unordered_map use; + int size; + /** Initialize your data structure here. */ + SummaryRanges() + { + size = 0; + } + + void addNum(int val) + { + if (use.count(val) != 0) + return; + use[val] = 1; + int i; + for (i = 0; i < size; i++) + if (val < ans[i][0]) + break; + if (i == 0) + { + if (size == 0) + { + ans.insert(ans.begin(), {val, val}); + size++; + } + else if (val + 1 == ans[i][0]) + ans[0][0] = val; + else + { + ans.insert(ans.begin(), {val, val}); + size++; + } + } + else if (i == size) + { + if (val - 1 == ans[i - 1][1]) + ans[i - 1][1] = val; + else + { + ans.push_back({val, val}); + size++; + } + } + else + { + if (val + 1 != ans[i][0] && val - 1 != ans[i - 1][1]) + { + ans.insert(ans.begin() + i, {val, val}); + size++; + } + else if (val + 1 == ans[i][0] && val - 1 == ans[i - 1][1]) + { + ans[i - 1][1] = ans[i][1]; + ans.erase(ans.begin() + i); + size--; + } + else if (val + 1 == ans[i][0]) + { + ans[i][0] = val; + } + else + { + ans[i - 1][1] = val; + } + } + } + + vector> getIntervals() + { + return ans; + } +}; + +/** + * Your SummaryRanges object will be instantiated and called as such: + * SummaryRanges* obj = new SummaryRanges(); + * obj->addNum(val); + * vector> param_2 = obj->getIntervals(); + */ ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/354.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/354.exercises/solution.md" index eb31064c696edbeec9b3aeb29b0b1243bc2d22e5..1118fc0f6952a9d26f18ade2e65caf36592bcfae 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/354.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/354.exercises/solution.md" @@ -37,7 +37,49 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int maxEnvelopes(vector> &envelopes) + { + sort(envelopes.begin(), envelopes.end(), comp); + + vector dp(envelopes.size(), 1); + + for (int i = 0; i < envelopes.size(); ++i) + { + for (int j = 0; j < i; ++j) + { + if (envelopes[i][1] > envelopes[j][1]) + dp[i] = dp[i] > dp[j] + 1 ? dp[i] : dp[j] + 1; + } + } + + int res = 0; + for (int i = 0; i < dp.size(); ++i) + res = res > dp[i] ? res : dp[i]; + + return res; + } + + static bool comp(const vector &a, const vector &b) + { + if (a[0] < b[0]) + return true; + else if (a[0] > b[0]) + return false; + else + { + if (a[1] > b[1]) + return true; + else + return false; + } + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/358.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/358.exercises/config.json" deleted file mode 100644 index 34f65d0362e81a824691ce7d067cff91e3ba2f5d..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/358.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-ad9b15b133d24f708105a919c319fc22", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/358.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/358.exercises/solution.json" deleted file mode 100644 index 0cf0b2acbde026e1d4c99f072d085cebdaa41e15..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/358.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "a884968518654253a6f7d79946ef4351", - "author": "csdn.net", - "keywords": "贪心,哈希表,字符串,计数,排序,堆(优先队列)" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/358.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/358.exercises/solution.md" deleted file mode 100644 index 535f69c1190b634fd09fb9207703c9a56f3e70e1..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/358.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# K 距离间隔重排字符串 - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/363.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/363.exercises/solution.md" index bfd56ad12bd0f67dee052031e968239d4a71e19c..2de116311a9855a873a2b53179f997ce3ab2cd3b 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/363.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/363.exercises/solution.md" @@ -41,6 +41,46 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + int maxSumSubmatrix(vector> &mat, int k) + { + int m = mat.size(), n = mat[0].size(); + vector> sum(m + 1, vector(n + 1, 0)); + for (int i = 1; i <= m; i++) + { + for (int j = 1; j <= n; j++) + { + sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + mat[i - 1][j - 1]; + } + } + int ans = INT_MIN; + for (int top = 1; top <= m; top++) + { + for (int bot = top; bot <= m; bot++) + { + set st; + st.insert(0); + for (int r = 1; r <= n; r++) + { + int right = sum[bot][r] - sum[top - 1][r]; + auto left = st.lower_bound(right - k); + if (left != st.end()) + { + int cur = right - *left; + ans = max(ans, cur); + } + st.insert(right); + } + } + } + return ans; + } +}; ``` diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/381.exercises/config.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/381.exercises/config.json" deleted file mode 100644 index 47bce7c85b69c7d44f801b4d3be0bd43d9129660..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/381.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-a6b97887de884133a837b62ae85843c5", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/381.exercises/solution.json" "b/data_source/exercises/\345\233\260\351\232\276/cpp/381.exercises/solution.json" deleted file mode 100644 index 7612445838e090b145124b6b47623d3e19b6de09..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/381.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "194d9485ed0a402896a83d0aceb5b0f8", - "author": "csdn.net", - "keywords": "设计,数组,哈希表,数学,随机化" -} \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/381.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/381.exercises/solution.md" deleted file mode 100644 index b75c056d1dccae26db3e38d8263a085361831338..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/381.exercises/solution.md" +++ /dev/null @@ -1,69 +0,0 @@ -# O(1) 时间插入、删除和获取随机元素 - -

设计一个支持在平均 时间复杂度 O(1) , 执行以下操作的数据结构。

- -

注意: 允许出现重复元素。

- -
    -
  1. insert(val):向集合中插入元素 val。
  2. -
  3. remove(val):当 val 存在时,从集合中移除一个 val。
  4. -
  5. getRandom:从现有集合中随机获取一个元素。每个元素被返回的概率应该与其在集合中的数量呈线性相关。
  6. -
- -

示例:

- -
// 初始化一个空的集合。
-RandomizedCollection collection = new RandomizedCollection();
-
-// 向集合中插入 1 。返回 true 表示集合不包含 1 。
-collection.insert(1);
-
-// 向集合中插入另一个 1 。返回 false 表示集合包含 1 。集合现在包含 [1,1] 。
-collection.insert(1);
-
-// 向集合中插入 2 ,返回 true 。集合现在包含 [1,1,2] 。
-collection.insert(2);
-
-// getRandom 应当有 2/3 的概率返回 1 ,1/3 的概率返回 2 。
-collection.getRandom();
-
-// 从集合中删除 1 ,返回 true 。集合现在包含 [1,2] 。
-collection.remove(1);
-
-// getRandom 应有相同概率返回 1 和 2 。
-collection.getRandom();
-
- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\345\233\260\351\232\276/cpp/391.exercises/solution.md" "b/data_source/exercises/\345\233\260\351\232\276/cpp/391.exercises/solution.md" index 6eb12aaa6394a2793d575aa158a3fd9ff58c29df..da0da4b58a1fb37762b8bae99e5fe64a372e707b 100644 --- "a/data_source/exercises/\345\233\260\351\232\276/cpp/391.exercises/solution.md" +++ "b/data_source/exercises/\345\233\260\351\232\276/cpp/391.exercises/solution.md" @@ -71,6 +71,50 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + bool isRectangleCover(vector> &ret) + { + set> s; + int x1 = INT_MAX, y1 = INT_MAX, x2 = INT_MIN, y2 = INT_MIN, area = 0; + for (int i = 0; i < ret.size(); ++i) + { + x1 = min(ret[i][0], x1); + x2 = max(ret[i][2], x2); + y1 = min(ret[i][1], y1); + y2 = max(ret[i][3], y2); + area += (ret[i][2] - ret[i][0]) * (ret[i][3] - ret[i][1]); + + if (s.find({ret[i][0], ret[i][1]}) == s.end()) + s.insert({ret[i][0], ret[i][1]}); + else + s.erase({ret[i][0], ret[i][1]}); + + if (s.find({ret[i][2], ret[i][3]}) == s.end()) + s.insert({ret[i][2], ret[i][3]}); + else + s.erase({ret[i][2], ret[i][3]}); + + if (s.find({ret[i][0], ret[i][3]}) == s.end()) + s.insert({ret[i][0], ret[i][3]}); + else + s.erase({ret[i][0], ret[i][3]}); + + if (s.find({ret[i][2], ret[i][1]}) == s.end()) + s.insert({ret[i][2], ret[i][1]}); + else + s.erase({ret[i][2], ret[i][1]}); + } + + if (s.size() != 4 || !s.count({x1, y1}) || !s.count({x1, y2}) || !s.count({x2, y1}) || !s.count({x2, y2})) + return false; + return area == (x2 - x1) * (y2 - y1); + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/101.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/101.exercises/solution.md" index df917aeb1cced48a180d4a55d94b5d7c5409c439..747c823ac19b96203039c91914092b38fbbc1398 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/101.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/101.exercises/solution.md" @@ -34,8 +34,37 @@ ## template ```cpp - - +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + bool haha(TreeNode *l, TreeNode *r) + { + if (!l && !r) + return true; + if (!l || !r) + return false; + if (l->val != r->val) + return false; + return haha(l->right, r->left) & haha(l->left, r->right); + } + bool isSymmetric(TreeNode *root) + { + if (!root) + return true; + return haha(root->left, root->right); + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/104.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/104.exercises/solution.md" index 01df0d46c4d4c41f633af8c2c706d685e88e41fe..dd3a1892c265cd372d21063326cf72490d5332e3 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/104.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/104.exercises/solution.md" @@ -22,7 +22,34 @@ ```cpp - +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + int maxDepth(TreeNode *root) + { + int depth = 0; + if (root == NULL) + { + return 0; + } + else + { + depth = max(maxDepth(root->left), maxDepth(root->right)); + return 1 + depth; + } + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/108.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/108.exercises/solution.md" index e83a5f432cf6edfbcff056c41f309c30214f5aed..e193cacbc3cb435470d7bbb084cd93b8410bf9e1 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/108.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/108.exercises/solution.md" @@ -37,8 +37,36 @@ ## template ```cpp - - +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + TreeNode *sortedArrayToBST(vector &nums) + { + return dfs(nums, 0, nums.size() - 1); + } + + TreeNode *dfs(vector &nums, int left, int right) + { + if (left > right) + return NULL; + int mid = (left + right) / 2; + TreeNode *t = new TreeNode(nums[mid]); + t->left = dfs(nums, left, mid - 1); + t->right = dfs(nums, mid + 1, right); + return t; + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/110.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/110.exercises/solution.md" index 32e9a8a54d4d5f577dd2d406c605a8bda16f61cc..56a72c7157de3f871a550157e8c9929344e66f20 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/110.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/110.exercises/solution.md" @@ -44,8 +44,39 @@ ## template ```cpp - - +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + int depth(TreeNode *root) + { + if (root == NULL) + return 0; + int left = depth(root->left); + int right = depth(root->right); + return max(left, right) + 1; + } + + bool isBalanced(TreeNode *root) + { + if (root == NULL) + return true; + if (abs(depth(root->left) - depth(root->right)) > 1) + return false; + else + return isBalanced(root->left) && isBalanced(root->right); + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/111.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/111.exercises/solution.md" index 2abba4a7c1a8b5f4005b3804f591c2a1ef53aece..527bf93653ace3589d306515f19376dba323167c 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/111.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/111.exercises/solution.md" @@ -37,6 +37,29 @@ ```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + int minDepth(TreeNode *root) + { + if (!root) + return 0; + int left = minDepth(root->left); + int right = minDepth(root->right); + return (left && right) ? 1 + min(left, right) : 1 + left + right; + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/112.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/112.exercises/solution.md" index 5130c4148dadf87f0041941c3d6162eb67ac6ed3..b42acb06bfbfdd1639ae51cec00097c6e87e6871 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/112.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/112.exercises/solution.md" @@ -42,7 +42,51 @@ ```cpp - +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + bool hasPathSum(TreeNode *root, int sum) + { + bool flag = false; + backTrack(root, sum, flag); + return flag; + } + + void backTrack(TreeNode *root, int sum, bool &flag) + { + if (!root) + { + return; + } + + if (!root->left && !root->right) + { + sum -= root->val; + if (sum == 0) + { + flag = true; + } + sum += root->val; + return; + } + + sum -= root->val; + backTrack(root->left, sum, flag); + backTrack(root->right, sum, flag); + sum += root->val; + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/118.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/118.exercises/solution.md" index 4f7f33ed1ed3ca9fe1d6195c3c18ae38526b37f7..e9885e58509b02734101f283f0da25635864ad0e 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/118.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/118.exercises/solution.md" @@ -34,8 +34,48 @@ ## template ```cpp - - +#include +using namespace std; + +class Solution +{ +public: + vector> generate(int numRows) + { + + if (numRows <= 0) + { + return {}; + } + if (numRows == 1) + { + return {{1}}; + } + if (numRows == 2) + { + return {{1}, {1, 1}}; + } + + vector> res = {{1}, {1, 1}}; + vector arr; + int row = 1; + while (row < numRows - 1) + { + arr.push_back(1); + for (int i = 0; i < res[row].size() - 1; i++) + { + int temp = 0; + temp = res[row][i] + res[row][i + 1]; + arr.push_back(temp); + } + arr.push_back(1); + res.push_back(arr); + arr.clear(); + row++; + } + return res; + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/119.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/119.exercises/solution.md" index b07cc66b0b280c932db6d5e48a272db1a164d299..de78c7844a17782366bf1425b5b6cbe79fe3d03e 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/119.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/119.exercises/solution.md" @@ -47,8 +47,25 @@ ## template ```cpp - - +#include +using namespace std; + +class Solution +{ +public: + vector getRow(int rowIndex) + { + vector res(rowIndex + 1, 1); + for (int i = 0; i < rowIndex + 1; ++i) + { + for (int j = i - 1; j > 0; --j) + { + res[j] = res[j] + res[j - 1]; + } + } + return res; + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/121.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/121.exercises/solution.md" index 551715b5ddeb6455b83188751575d6a5266d87db..55acb60b0b0bb8950e32a4a72fdbc6ae46f882aa 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/121.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/121.exercises/solution.md" @@ -39,7 +39,31 @@ ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int maxProfit(vector &prices) + { + int profit = INT_MIN; + int buy = INT_MAX; + for (int i = 0; i < prices.size(); i++) + { + int temp = prices[i] - buy; + if (temp > profit) + { + profit = temp; + } + if (temp < 0) + { + buy = prices[i]; + } + } + return (profit > 0) ? profit : 0; + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/122.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/122.exercises/solution.md" index dbbd48436b347c904222222afe035820950e0737..b52f61392b66474d0f59237d53f2939ea6537978 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/122.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/122.exercises/solution.md" @@ -46,7 +46,25 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int maxProfit(vector &prices) + { + if (prices.empty()) + return 0; + int cnt = 0; + for (int i = 0; i < prices.size() - 1; ++i) + { + if (prices[i] < prices[i + 1]) + cnt += prices[i + 1] - prices[i]; + } + return cnt; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/125.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/125.exercises/solution.md" index 6ee1619417c5266fc1346b93c1779bdd3ff4d187..3fc65a8156a06fc6ff2dca46ce0c753fcf131e56 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/125.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/125.exercises/solution.md" @@ -36,7 +36,42 @@ ```cpp - +#include +using namespace std; + +class Solution +{ +public: + bool isPalindrome(string s) + { + int left = 0, right; + if ((right = s.size()) == 0) + { + return true; + } + while (left < right) + { + while (left < right && !isalnum(s[left])) + { + left++; + } + while (left < right && !isalnum(s[right])) + { + right--; + } + if (left < right) + { + if (tolower(s[left]) != tolower(s[right])) + { + return false; + } + } + left++; + right--; + } + return true; + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/136.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/136.exercises/solution.md" index 90fa03cc9d42c2c8fc6c1624d798275528b91528..eb83a100dbfd91bb34eeba4f950b7582f20961df 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/136.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/136.exercises/solution.md" @@ -22,7 +22,22 @@ ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int singleNumber(vector &nums) + { + int res = 0; + for (int i = 0; i < nums.size(); i++) + { + res ^= nums[i]; + } + return res; + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/141.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/141.exercises/solution.md" index ab137757341515f392b96a537ae13bf02451cb83..6d587b1cc6d884e9cbb1571da110bbbb9a945d0e 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/141.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/141.exercises/solution.md" @@ -55,8 +55,38 @@ ## template ```cpp - - +#include +using namespace std; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + bool hasCycle(ListNode *head) + { + + ListNode *faster = head; + ListNode *slower = head; + + if (head == NULL) + return false; + + while (faster != NULL && faster->next != NULL) + { + faster = faster->next->next; + slower = slower->next; + if (faster == slower) + return true; + } + return false; + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/144.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/144.exercises/solution.md" index c83f9f1d5a9f322bdfb710fbd226f0a02a6c3f62..4b9548af0cff603632941f732a3006239b8e1753 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/144.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/144.exercises/solution.md" @@ -57,7 +57,30 @@ ```cpp - +#include +using namespace std; + +class Solution +{ +private: + void rec(TreeNode *root, vector &ret) + { + if (root != NULL) + { + rec(root->right, ret); + rec(root->left, ret); + ret.push_back(root->val); + } + } + +public: + vector postorderTraversal(TreeNode *root) + { + vector ret; + rec(root, ret); + return ret; + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/145.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/145.exercises/solution.md" index ec26faa0a839bd42725b5807dd9eae564b037ff1..94eb07c7fddc194bbda5473d952e9ad075f3b214 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/145.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/145.exercises/solution.md" @@ -20,7 +20,27 @@ ```cpp - +#include +using namespace std; + +class Solution +{ +public: + vector postorderTraversal(TreeNode *root) + { + dfs(root); + return temp; + } + void dfs(TreeNode *root) + { + if (root == NULL) + return; + dfs(root->left); + dfs(root->right); + temp.push_back(root->val); + } + vector temp; +}; ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/155.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/155.exercises/solution.md" index 26f358d89edd6f491a5ced57753675155906646d..962ff544283ce0af8233df97ae225c78fbf5e214 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/155.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/155.exercises/solution.md" @@ -43,7 +43,44 @@ minStack.getMin(); --> 返回 -2. ## template ```cpp - +#include +using namespace std; + +class MinStack +{ +public: + stack s; + stack min; + /** initialize your data structure here. */ + MinStack() + { + } + + void push(int x) + { + s.push(x); + if (min.empty() || x <= min.top()) + { + min.push(x); + } + } + + void pop() + { + if (s.top() == min.top()) + min.pop(); + s.pop(); + } + + int top() + { + return s.top(); + } + int getMin() + { + return min.top(); + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/157.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/157.exercises/config.json" deleted file mode 100644 index 9d8d8e1dcfa467e43ea1736baf3a098264b7cb65..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/157.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-4de24aa0c7344f25857309f39049cdd6", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/157.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/157.exercises/solution.json" deleted file mode 100644 index 1a4d8aed029f672afd966022cf687c542ac3bfe6..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/157.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "4e5af08303f447cbb36a145d372a4c3e", - "author": "csdn.net", - "keywords": "字符串,交互,模拟" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/157.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/157.exercises/solution.md" deleted file mode 100644 index 38123e0161d32e3549cb567219ca54b108a4f188..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/157.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 用 Read4 读取 N 个字符 - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/160.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/160.exercises/solution.md" index cf44caebfbfaa915134fa8d38972f33823fa6283..818e6a2e20b34f40749e4b8edd5c262a3ec9f1a8 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/160.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/160.exercises/solution.md" @@ -72,6 +72,30 @@ ```cpp +#include +using namespace std; + +class Solution +{ +public: + ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) + { + + if (!headA || !headB) + { + return NULL; + } + + ListNode *cur1 = headA; + ListNode *cur2 = headB; + while (cur1 != cur2) + { + cur1 = cur1 ? cur1->next : headB; + cur2 = cur2 ? cur2->next : headA; + } + return cur1; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/163.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/163.exercises/config.json" deleted file mode 100644 index d1c63e702ba8413a15bb27b63616112cce5e4552..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/163.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-5ade162d0e4f4101a1b2c496cc8dda01", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/163.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/163.exercises/solution.json" deleted file mode 100644 index 5a752818e2a7ee5e1255abf2c39b10505800b5ae..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/163.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "ff805edfb4704a099d16f5b37079956e", - "author": "csdn.net", - "keywords": "数组" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/163.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/163.exercises/solution.md" deleted file mode 100644 index 963340c37111885068f7d9ec6d006add762d41de..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/163.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 缺失的区间 - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/167.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/167.exercises/solution.md" index ca82d49dbf8c59f9a761b979b46307bc734fd205..38ace9cf84394b3d58c7ef77c3fb10b6f30909ca 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/167.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/167.exercises/solution.md" @@ -46,7 +46,34 @@ ```cpp - +#include +using namespace std; + +class Solution +{ +public: + vector twoSum(vector &numbers, int target) + { + int low = 0, high = numbers.size() - 1; + while (low < high) + { + int sum = numbers[low] + numbers[high]; + if (sum == target) + { + return {low + 1, high + 1}; + } + if (sum < target) + { + ++low; + } + else + { + --high; + } + } + return {-1, -1}; + } +} ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/168.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/168.exercises/solution.md" index d20ff63b91c97f4cf5ba459a1f282a8850b3dc88..6e6ad1ee43c310dbcce58ba992ef482f8933f6ec 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/168.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/168.exercises/solution.md" @@ -57,7 +57,31 @@ AB -> 28 ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + string convertToTitle(int n) + { + string res; + while (n) + { + int temp = n % 26; + n /= 26; + if (temp) + res.push_back('A' + temp - 1); + else + { + res.push_back('Z'); + n--; + } + } + reverse(res.begin(), res.end()); + return res; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/169.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/169.exercises/solution.md" index dbe3413d8124bfb041edd7b07bf8f2f748166be7..fb2b1813d5fbaa74d161ca3da5ad4009bbbadb50 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/169.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/169.exercises/solution.md" @@ -32,7 +32,28 @@ ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int majorityElement(vector &nums) + { + unordered_map counts; + int majority = 0, cnt = 0; + for (int num : nums) + { + ++counts[num]; + if (counts[num] > cnt) + { + majority = num; + cnt = counts[num]; + } + } + return majority; + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/170.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/170.exercises/config.json" deleted file mode 100644 index 35f0e4837153e2946e156d9321cc37144ae28ab5..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/170.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-9a10dbfc78084378b9158b62dd73cbf6", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/170.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/170.exercises/solution.json" deleted file mode 100644 index 34ba6f61d121bbbb84d6c17694fa538feb836d03..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/170.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "b2bddd35d61c408d9282619451a3f324", - "author": "csdn.net", - "keywords": "设计,数组,哈希表,双指针,数据流" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/170.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/170.exercises/solution.md" deleted file mode 100644 index a738157a21f773260ecc10201e6e0907a3ad38ab..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/170.exercises/solution.md" +++ /dev/null @@ -1,36 +0,0 @@ -# 两数之和 III - - - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/171.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/171.exercises/solution.md" index 309a9f2902e3568d9bf72019afc42cf3f7e13ddc..f9757c1eeb79b51b751792e4b8f4e95120bc9fe2 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/171.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/171.exercises/solution.md" @@ -60,7 +60,24 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int titleToNumber(string s) + { + + long num = 0; + + for (int i = 0; i < s.size(); i++) + { + num = (num * 26) + (s[i] - 64); + } + return num; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/172.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/172.exercises/solution.md" index c84ae8bb20591de183098f31fc6ec0878c68ea1c..3e5d8db58a343703664e0dbcfabe65bf19f290a3 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/172.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/172.exercises/solution.md" @@ -45,6 +45,35 @@ ## template ```cpp +#include +using namespace std; + +class Solution +{ +public: + int trailingZeroes(int n) + { + int numOfZeros = 0; + + while (n > 0) + { + numOfZeros += numOf5(n); + n--; + } + + return numOfZeros; + } + int numOf5(int num) + { + int count = 0; + while ((num > 1) && (num % 5 == 0)) + { + count++; + num /= 5; + } + return count; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/175.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/175.exercises/config.json" deleted file mode 100644 index ad10ecd9f45d8e90ad497f633e8fc1802dd7f921..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/175.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-85f7b312e21846f69643bb88236a2bdf", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/175.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/175.exercises/solution.json" deleted file mode 100644 index d6ec7a98d88ddf68ae25da359b4dcdd8ffba8087..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/175.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "dd9e054c96174629b626b0321a29c566", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/175.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/175.exercises/solution.md" deleted file mode 100644 index d49dd49f6df0e14c0142158e30cd82f49cc3c299..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/175.exercises/solution.md" +++ /dev/null @@ -1,69 +0,0 @@ -# 组合两个表 - -

表1: Person

- -
+-------------+---------+
-| 列名         | 类型     |
-+-------------+---------+
-| PersonId    | int     |
-| FirstName   | varchar |
-| LastName    | varchar |
-+-------------+---------+
-PersonId 是上表主键
-
- -

表2: Address

- -
+-------------+---------+
-| 列名         | 类型    |
-+-------------+---------+
-| AddressId   | int     |
-| PersonId    | int     |
-| City        | varchar |
-| State       | varchar |
-+-------------+---------+
-AddressId 是上表主键
-
- -

 

- -

编写一个 SQL 查询,满足条件:无论 person 是否有地址信息,都需要基于上述两表提供 person 的以下信息:

- -

 

- -
FirstName, LastName, City, State
-
- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/176.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/176.exercises/config.json" deleted file mode 100644 index 6a908bbf5ba9ac49b5c8ee67d979d7fce5d99c25..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/176.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-f292aee831624f71bbffe40a7326e60c", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/176.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/176.exercises/solution.json" deleted file mode 100644 index ec26066627ebccc2646df4ec4e69d85da9f79ed4..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/176.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "5b3f07f1ef3e468aae341b4bd2a98e6e", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/176.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/176.exercises/solution.md" deleted file mode 100644 index 0f1720ca97a92219a68c511941ef4d8b649d32dc..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/176.exercises/solution.md" +++ /dev/null @@ -1,55 +0,0 @@ -# 第二高的薪水 - -

编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) 。

- -
+----+--------+
-| Id | Salary |
-+----+--------+
-| 1  | 100    |
-| 2  | 200    |
-| 3  | 300    |
-+----+--------+
-
- -

例如上述 Employee 表,SQL查询应该返回 200 作为第二高的薪水。如果不存在第二高的薪水,那么查询应返回 null

- -
+---------------------+
-| SecondHighestSalary |
-+---------------------+
-| 200                 |
-+---------------------+
-
- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/181.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/181.exercises/config.json" deleted file mode 100644 index d846acfdfa0df164b4215198e5a6a25b43ef2716..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/181.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-8cb377183b7f43e494561b64ebb63857", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/181.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/181.exercises/solution.json" deleted file mode 100644 index 7481971eea75b028e5e7449c6896b106cb857a79..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/181.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "d6c4a46b82b843559ac48dae21bcfe29", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/181.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/181.exercises/solution.md" deleted file mode 100644 index f2a609c10f675be7dbd6be65bdbafcab0b165798..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/181.exercises/solution.md" +++ /dev/null @@ -1,56 +0,0 @@ -# 超过经理收入的员工 - -

Employee 表包含所有员工,他们的经理也属于员工。每个员工都有一个 Id,此外还有一列对应员工的经理的 Id。

- -
+----+-------+--------+-----------+
-| Id | Name  | Salary | ManagerId |
-+----+-------+--------+-----------+
-| 1  | Joe   | 70000  | 3         |
-| 2  | Henry | 80000  | 4         |
-| 3  | Sam   | 60000  | NULL      |
-| 4  | Max   | 90000  | NULL      |
-+----+-------+--------+-----------+
-
- -

给定 Employee 表,编写一个 SQL 查询,该查询可以获取收入超过他们经理的员工的姓名。在上面的表格中,Joe 是唯一一个收入超过他的经理的员工。

- -
+----------+
-| Employee |
-+----------+
-| Joe      |
-+----------+
-
- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/182.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/182.exercises/config.json" deleted file mode 100644 index b89972c464425a37bc99daf2a80b3d54e88849e4..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/182.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-54c93f55f2ff4886b15ec70c9f7a7520", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/182.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/182.exercises/solution.json" deleted file mode 100644 index 409191f35d6624b5db6d974f54703e3422431d58..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/182.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "9978a8ccf34d47a9b9e08644fbca7f80", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/182.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/182.exercises/solution.md" deleted file mode 100644 index 08179617468cc2fa3b0381b3d7772229619ef4a3..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/182.exercises/solution.md" +++ /dev/null @@ -1,59 +0,0 @@ -# 查找重复的电子邮箱 - -

编写一个 SQL 查询,查找 Person 表中所有重复的电子邮箱。

- -

示例:

- -
+----+---------+
-| Id | Email   |
-+----+---------+
-| 1  | a@b.com |
-| 2  | c@d.com |
-| 3  | a@b.com |
-+----+---------+
-
- -

根据以上输入,你的查询应返回以下结果:

- -
+---------+
-| Email   |
-+---------+
-| a@b.com |
-+---------+
-
- -

说明:所有电子邮箱都是小写字母。

- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/183.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/183.exercises/config.json" deleted file mode 100644 index 8e0379607243dc69ed2192b8868c5ef7d31e47ac..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/183.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-bf76bddb51ea4b049b9eaa7441aa6588", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/183.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/183.exercises/solution.json" deleted file mode 100644 index 15905b02ef91293d6a88a7a5ec19a73062d03961..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/183.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "0a7c83632c9544f9aa006e8bd4519510", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/183.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/183.exercises/solution.md" deleted file mode 100644 index 92fe212b614a1fb3d5f1e823aaa96bb7ef482ac4..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/183.exercises/solution.md" +++ /dev/null @@ -1,69 +0,0 @@ -# 从不订购的客户 - -

某网站包含两个表,Customers 表和 Orders 表。编写一个 SQL 查询,找出所有从不订购任何东西的客户。

- -

Customers 表:

- -
+----+-------+
-| Id | Name  |
-+----+-------+
-| 1  | Joe   |
-| 2  | Henry |
-| 3  | Sam   |
-| 4  | Max   |
-+----+-------+
-
- -

Orders 表:

- -
+----+------------+
-| Id | CustomerId |
-+----+------------+
-| 1  | 3          |
-| 2  | 1          |
-+----+------------+
-
- -

例如给定上述表格,你的查询应返回:

- -
+-----------+
-| Customers |
-+-----------+
-| Henry     |
-| Max       |
-+-----------+
-
- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/190.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/190.exercises/solution.md" index 223040b7a1e0d70c974ba2b0b307720f3665a521..d62bba09387b08898f9133ed45f08b41097085ff 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/190.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/190.exercises/solution.md" @@ -43,7 +43,26 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + uint32_t reverseBits(uint32_t n) + { + uint32_t res = 0; + + for (int i = 0; i < 32; i++) + { + res <<= 1; + res |= n & 1; + n >>= 1; + } + + return res; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/191.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/191.exercises/solution.md" index 633e24d908cbca00aac19fb3c4ea6f9217a3c6ff..e1880f15e5a818224870a10f42009a771e3a9a9e 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/191.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/191.exercises/solution.md" @@ -59,7 +59,27 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int hammingWeight(uint32_t n) + { + int count = 0; + uint32_t res = 1; + for (int i = 0; i < 32; i++) + { + if (res & n) + { + count++; + } + n >>= 1; + } + return count; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/193.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/193.exercises/config.json" deleted file mode 100644 index 67b0edcb778fb6d1b0fb57958f41f2713330bd14..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/193.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-1352eaf10ae34a0ca9aa92949beb3c8d", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/193.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/193.exercises/solution.json" deleted file mode 100644 index c7e330a1b24f9558525606641a64d456bc093fce..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/193.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "ca6c196606004fa4ab6e8463b4d867fb", - "author": "csdn.net", - "keywords": "shell" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/193.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/193.exercises/solution.md" deleted file mode 100644 index c6c2257d613b7fd7a10adfc7b8778d1adf6e32c2..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/193.exercises/solution.md" +++ /dev/null @@ -1,60 +0,0 @@ -# 有效电话号码 - -

给定一个包含电话号码列表(一行一个电话号码)的文本文件 file.txt,写一个单行 bash 脚本输出所有有效的电话号码。

- -

你可以假设一个有效的电话号码必须满足以下两种格式: (xxx) xxx-xxxx 或 xxx-xxx-xxxx。(x 表示一个数字)

- -

你也可以假设每行前后没有多余的空格字符。

- -

 

- -

示例:

- -

假设 file.txt 内容如下:

- -
-987-123-4567
-123 456 7890
-(123) 456-7890
-
- -

你的脚本应当输出下列有效的电话号码:

- -
-987-123-4567
-(123) 456-7890
-
- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/195.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/195.exercises/config.json" deleted file mode 100644 index 184155206bfeae56b7afb860b6533fc17405b011..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/195.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-c78b9d1362f846a3a49e8af24ce85cc3", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/195.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/195.exercises/solution.json" deleted file mode 100644 index bfac1182c7d80ec61364b565a83a9c03de4255e8..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/195.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "522b8d3fc3c04c9d9926dc1b65a18403", - "author": "csdn.net", - "keywords": "shell" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/195.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/195.exercises/solution.md" deleted file mode 100644 index 1a86970af6a826135688342ddc74863811f09538..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/195.exercises/solution.md" +++ /dev/null @@ -1,62 +0,0 @@ -# 第十行 - -

给定一个文本文件 file.txt,请只打印这个文件中的第十行。

- -

示例:

- -

假设 file.txt 有如下内容:

- -
Line 1
-Line 2
-Line 3
-Line 4
-Line 5
-Line 6
-Line 7
-Line 8
-Line 9
-Line 10
-
- -

你的脚本应当显示第十行:

- -
Line 10
-
- -

说明:
-1. 如果文件少于十行,你应当输出什么?
-2. 至少有三种不同的解法,请尝试尽可能多的方法来解题。

- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/196.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/196.exercises/config.json" deleted file mode 100644 index 5d9deaea7dd0ec1ac320b474802165e0c731b8be..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/196.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-807994a6110843e28221362d4a038abd", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/196.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/196.exercises/solution.json" deleted file mode 100644 index 2424cfb66dab46789aa3d9336202bb7949a63444..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/196.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "c2759b89ec514f61b350829d2197e361", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/196.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/196.exercises/solution.md" deleted file mode 100644 index 54d2d567dedd117ecc3a7dc5cbdb6e6a4b7a6773..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/196.exercises/solution.md" +++ /dev/null @@ -1,66 +0,0 @@ -# 删除重复的电子邮箱 - -

编写一个 SQL 查询,来删除 Person 表中所有重复的电子邮箱,重复的邮箱里只保留 Id 最小 的那个。

- -
+----+------------------+
-| Id | Email            |
-+----+------------------+
-| 1  | john@example.com |
-| 2  | bob@example.com  |
-| 3  | john@example.com |
-+----+------------------+
-Id 是这个表的主键。
-
- -

例如,在运行你的查询语句之后,上面的 Person 表应返回以下几行:

- -
+----+------------------+
-| Id | Email            |
-+----+------------------+
-| 1  | john@example.com |
-| 2  | bob@example.com  |
-+----+------------------+
-
- -

 

- -

提示:

- -
    -
  • 执行 SQL 之后,输出是整个 Person 表。
  • -
  • 使用 delete 语句。
  • -
- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/197.exercises/config.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/197.exercises/config.json" deleted file mode 100644 index e0c18f42da877a7e9069f31b49240ca76d47d066..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/197.exercises/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "dailycode-6ca678258ebb4b49b1ed247761ee7594", - "keywords": [], - "children": [], - "keywords_must": [], - "keywords_forbid": [], - "export": [ - "solution.json" - ] -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/197.exercises/solution.json" "b/data_source/exercises/\347\256\200\345\215\225/cpp/197.exercises/solution.json" deleted file mode 100644 index de1ff0667ba43fb00f6afa07ff52c1211ef95d23..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/197.exercises/solution.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "source": "solution.md", - "exercise_id": "d01e6eb74ba84d4d9273ceaafd110640", - "author": "csdn.net", - "keywords": "数据库" -} \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/197.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/197.exercises/solution.md" deleted file mode 100644 index 36c0b381be8997196ad85a05a9e7b155c9bf815d..0000000000000000000000000000000000000000 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/197.exercises/solution.md" +++ /dev/null @@ -1,82 +0,0 @@ -# 上升的温度 - -
-
-

Weather

- -
-+---------------+---------+
-| Column Name   | Type    |
-+---------------+---------+
-| id            | int     |
-| recordDate    | date    |
-| temperature   | int     |
-+---------------+---------+
-id 是这个表的主键
-该表包含特定日期的温度信息
- -

 

- -

编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 id

- -

返回结果 不要求顺序

- -

查询结果格式如下例:

- -
-Weather
-+----+------------+-------------+
-| id | recordDate | Temperature |
-+----+------------+-------------+
-| 1  | 2015-01-01 | 10          |
-| 2  | 2015-01-02 | 25          |
-| 3  | 2015-01-03 | 20          |
-| 4  | 2015-01-04 | 30          |
-+----+------------+-------------+
-
-Result table:
-+----+
-| id |
-+----+
-| 2  |
-| 4  |
-+----+
-2015-01-02 的温度比前一天高(10 -> 25)
-2015-01-04 的温度比前一天高(20 -> 30)
-
-
-
- - -## template - -```cpp - - -``` - -## 答案 - -```cpp - -``` - -## 选项 - -### A - -```cpp - -``` - -### B - -```cpp - -``` - -### C - -```cpp - -``` \ No newline at end of file diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/202.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/202.exercises/solution.md" index e590fdcd3f2f4982c6dde87029cab46c077ab6d2..10954e2884bbeb2bdb400baac55eafbe859ad34c 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/202.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/202.exercises/solution.md" @@ -46,7 +46,33 @@ ```cpp - +#include +using namespace std; + +class Solution +{ +public: + bool isHappy(int n) + { + set s; + while (n != 1) + { + int t = 0; + while (n) + { + t += (n % 10) * (n % 10); + n /= 10; + } + + int size = s.size(); + s.insert(t); + if (size == s.size()) + return false; + n = t; + } + return true; + } +}; ``` ## 答案 diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/203.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/203.exercises/solution.md" index 86b63d1b08836613db09ca2fecf65cc95f961d9b..4b34eddad1d3a5b53503fb1a9b3657f7768e5aa9 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/203.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/203.exercises/solution.md" @@ -38,7 +38,42 @@ ## template ```cpp - +#include +using namespace std; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + ListNode *removeElements(ListNode *head, int val) + { + ListNode *dumynode = new ListNode(0); + dumynode->next = head; + ListNode *fast = dumynode->next; + ListNode *slow = dumynode; + while (fast != NULL) + { + if (fast->val == val) + { + slow->next = slow->next->next; + } + else + { + slow = slow->next; + } + fast = fast->next; + } + ListNode *ret = dumynode->next; + delete dumynode; + return ret; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/204.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/204.exercises/solution.md" index d395f8c9928afbf2f363d7c6f782feec87542d0f..5aec7be0c0d725dd8cb6ffc09807c59308a3eb60 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/204.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/204.exercises/solution.md" @@ -35,7 +35,30 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + int countPrimes(int n) + { + vector primesMap(n, true); + int count = 0; + for (int i = 2; i < n; i++) + { + if (primesMap[i]) + { + count++; + for (int j = 2 * i; j < n; j += i) + { + primesMap[j] = false; + } + } + } + return count; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/205.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/205.exercises/solution.md" index 46bdb03d58876bf9ededc4ca74ac88c877b38967..b975a7446ef41fee5fb3ee74dc5d5f4a76750842 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/205.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/205.exercises/solution.md" @@ -39,7 +39,35 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + bool isIsomorphic(string s, string t) + { + vector m(128, -1); + for (int i = 0; i < s.size(); ++i) + { + if (m[s[i]] != -1) + { + if (m[s[i]] != t[i]) + return false; + } + else + { + for (auto v : m) + { + if (v == t[i]) + return false; + } + m[s[i]] = t[i]; + } + } + return true; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/206.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/206.exercises/solution.md" index 3413501cdbec6bfab2ac56a18b9dbe24f6156efc..9fd32f3f95c9da6f5543309195259993612160e1 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/206.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/206.exercises/solution.md" @@ -45,6 +45,42 @@ ## template ```cpp +#include +using namespace std; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + ListNode *reverseList(ListNode *head) + { + if (head == NULL) + return NULL; + ListNode *node = NULL; + ListNode *temp = head; + ListNode *temp1 = head; + while (true) + { + if (temp->next == NULL) + { + temp1 = temp; + temp1->next = node; + break; + } + temp1 = temp; + temp = temp->next; + temp1->next = node; + node = temp1; + } + return temp1; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/217.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/217.exercises/solution.md" index 61e1f226c270a6cf03bab28a42f2cce49c89b38c..a56993f859ae443d5cf342385c797d01e32ef7cd 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/217.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/217.exercises/solution.md" @@ -28,7 +28,29 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + bool containsDuplicate(vector &nums) + { + if (nums.empty()) + { + return false; + } + sort(nums.begin(), nums.begin() + nums.size()); + for (int i = 0; i < nums.size() - 1; i++) + { + if (nums[i] == nums[i + 1]) + { + return true; + } + } + return false; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/219.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/219.exercises/solution.md" index 8ccabe1589e43c75ef1e734fee6f84e76be0afcc..7f4bbe9e9a2d7784d168e9ac6e2a0635b018f94d 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/219.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/219.exercises/solution.md" @@ -23,7 +23,32 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + bool containsNearbyDuplicate(vector &nums, int k) + { + int n = nums.size(), idx = 0; + unordered_map nmap; + for (int i = 0; i < n; ++i) + { + auto iter = nmap.find(nums[i]); + if (iter != nmap.end()) + { + if (i - iter->second <= k) + return true; + else + iter->second = i; + } + else + nmap[nums[i]] = i; + } + return false; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/225.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/225.exercises/solution.md" index ab8decdbee8fc4ddc2c6f272eb21d2286e561e57..07a8ea7ca0b6a62f8605e636229f3f0e16c5cebb 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/225.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/225.exercises/solution.md" @@ -58,7 +58,48 @@ myStack.empty(); // 返回 False ## template ```cpp - +#include +using namespace std; + +class MyStack +{ +public: + MyStack() + { + } + void push(int x) + { + std::queue temp_queue; + temp_queue.push(x); + while (!_data.empty()) + { + temp_queue.push(_data.front()); + _data.pop(); + } + while (!temp_queue.empty()) + { + _data.push(temp_queue.front()); + temp_queue.pop(); + } + } + int pop() + { + int x = _data.front(); + _data.pop(); + return x; + } + int top() + { + return _data.front(); + } + bool empty() + { + return _data.empty(); + } + +private: + std::queue _data; +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/226.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/226.exercises/solution.md" index 7ce757a61ba1c80ca7cbd9762491cec42db865d6..65e7812370ad625806e0f069c5eb9653c701ac37 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/226.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/226.exercises/solution.md" @@ -29,7 +29,32 @@ ## template ```cpp - +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + TreeNode *invertTree(TreeNode *root) + { + if (!root) + { + return root; + } + TreeNode *temp = root->left; + root->left = invertTree(root->right); + root->right = invertTree(temp); + return root; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/228.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/228.exercises/solution.md" index 848b7680e23703e4ef7352dbab6e224a0428b454..7dd8f72164da8f250edfe2916eb489f49574bf37 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/228.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/228.exercises/solution.md" @@ -72,7 +72,31 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + vector summaryRanges(vector &nums) + { + int n = nums.size(); + vector ans; + int i = 0; + while (i < n) + { + int j = i; + while (j + 1 < n && nums[j + 1] == nums[j] + 1) + j++; + if (i == j) + ans.push_back(to_string(nums[i])); + else + ans.push_back(to_string(nums[i]) + "->" + to_string(nums[j])); + i = j + 1; + } + return ans; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/231.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/231.exercises/solution.md" index 04e0fa6ac3364282e39166185fdd7083bf557e0f..b2d9ce3c926eceb6370fb1baac6c231b72f62158 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/231.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/231.exercises/solution.md" @@ -59,7 +59,22 @@ ## template ```cpp - +#include +using namespace std; + +class Solution +{ +public: + bool isPowerOfTwo(int n) + { + int cur = 0; + for (int i = 0; i < 31; i++) + { + cur += (n >> i) & 1; + } + return n > 0 && cur == 1; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/232.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/232.exercises/solution.md" index 694c802d7f1496f50600825d83448c43cf0ce760..b3d46a38ff59e482180ca508a202da4a28732393 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/232.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/232.exercises/solution.md" @@ -65,7 +65,55 @@ myQueue.empty(); // return false ## template ```cpp - +#include +using namespace std; + +class MyQueue +{ +public: + /** Initialize your data structure here. */ + stack a, b; + + MyQueue() + { + } + + /** Push element x to the back of queue. */ + void push(int x) + { + while (!b.empty()) + { + a.push(b.top()); + b.pop(); + } + b.push(x); + while (!a.empty()) + { + b.push(a.top()); + a.pop(); + } + } + + /** Removes the element from in front of queue and returns that element. */ + int pop() + { + int res = b.top(); + b.pop(); + return res; + } + + /** Get the front element. */ + int peek() + { + return b.top(); + } + + /** Returns whether the queue is empty. */ + bool empty() + { + return b.empty(); + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/234.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/234.exercises/solution.md" index 318f8a6d1f384cc4cba1cf33eb449da4712f1031..2bd533e93583028741b4afbde7cdc0d6788db3fc 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/234.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/234.exercises/solution.md" @@ -35,7 +35,35 @@ ## template ```cpp - +#include +using namespace std; + +struct ListNode +{ + int val; + ListNode *next; + ListNode(int x) : val(x), next(NULL) {} +}; + +class Solution +{ +public: + bool isPalindrome(ListNode *head) + { + vector v; + while (head != NULL) + { + v.push_back(head->val); + head = head->next; + } + for (int i = 0; i < v.size(); i++) + { + if (v[i] != v[v.size() - i - 1]) + return false; + } + return true; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/cpp/235.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/cpp/235.exercises/solution.md" index 1ae987e64ac853e475011883913b9f7dc22df4a9..7ddce001c1764530dd92cc5e45a7419416b3bf5f 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/cpp/235.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/cpp/235.exercises/solution.md" @@ -36,6 +36,31 @@ ## template ```cpp +#include +using namespace std; + +struct TreeNode +{ + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(NULL), right(NULL) {} +}; + +class Solution +{ +public: + TreeNode *lowestCommonAncestor(TreeNode *root, TreeNode *p, TreeNode *q) + { + if (root == NULL) + return NULL; + if ((root->val > q->val) && (root->val > p->val)) + return lowestCommonAncestor(root->left, p, q); + else if ((root->val < q->val) && (root->val < p->val)) + return lowestCommonAncestor(root->right, p, q); + return root; + } +}; ``` diff --git "a/data_source/exercises/\347\256\200\345\215\225/java/101.exercises/solution.md" "b/data_source/exercises/\347\256\200\345\215\225/java/101.exercises/solution.md" index ced3ca9be0930db88f478b03f6ad96eb6b5c549a..de52d97d03d774de4b3bfc6d0ad7c52a1aa1a7fd 100644 --- "a/data_source/exercises/\347\256\200\345\215\225/java/101.exercises/solution.md" +++ "b/data_source/exercises/\347\256\200\345\215\225/java/101.exercises/solution.md" @@ -35,6 +35,37 @@ ```java +public class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } +} + +class Solution { + public boolean isSymmetric(TreeNode root) { + if (root == null) { + return true; + } + + return isSymmetric(root.left, root.right); + } + + public boolean isSymmetric(TreeNode n1, TreeNode n2) { + if (n1 == null || n2 == null) { + return n1 == n2; + } + + if (n1.val != n2.val) { + return false; + } + + return isSymmetric(n1.left, n2.right) && isSymmetric(n1.right, n2.left); + } +} ``` diff --git a/it_knowledge_helper.py b/it_knowledge_helper.py index abcb89d729c7133a6217a622696408b51e3525d6..cb276ac658d32336ab051ad5ec26113e2fb11b71 100644 --- a/it_knowledge_helper.py +++ b/it_knowledge_helper.py @@ -221,6 +221,7 @@ def update_it_konwledge(): answer = answer.strip() print(file) assert answer in choice_list_res + assert len(choice_list_res) >= 4 question_id = file_name choice_list_remove = [] for idx, val in enumerate(choice_list_res): diff --git a/src/tree.py b/src/tree.py index 0c58d32b0da0e7099c2d2804fc97cdc35b240e28..cdb50518b9fa2efbdc1905b547b67f83da0d3b97 100644 --- a/src/tree.py +++ b/src/tree.py @@ -411,7 +411,7 @@ class TreeWalker: def default_notebook(self): if self.enable_notebook is not None: return self.enable_notebook - if self.name in ["python", "java", "c"]: + if self.name in ["python", "java", "c", "dailycode"]: return True else: return False