上一页 1 2 3 4 5 6 7 8 9 10 ··· 25 下一页
思路 桶排序 将数组排序,放入各个对应的桶中,把各个空桶输出出来 代码: class Solution { public: vector<int> findDisappearedNumbers(vector<int>& nums) { sort(nums.begin(),nums.end()); v Read More
posted @ 2021-09-26 16:18 A-inspire Views(16) Comments(0) Diggs(0) Edit
思路 反向中序遍历二叉树,将结果进行累加。 代码: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int Read More
posted @ 2021-09-26 16:17 A-inspire Views(21) Comments(0) Diggs(0) Edit
代码: class Solution { int n,res = 0; public: void help(string&s,int left,int right) { while(left>=0&&right<n) { if(s[left--]==s[right++]) { ++res; } el Read More
posted @ 2021-09-26 16:16 A-inspire Views(16) Comments(0) Diggs(0) Edit
思路 在原始信息和哈希映射使用的实际键值之间建立映射关系,先将单词字母按照字母表的顺序进行排列,若排列的结果相同,则为字母异位词 代码 class Solution { public: vector<vector<string>> groupAnagrams(vector<string>& strs Read More
posted @ 2021-09-26 16:15 A-inspire Views(16) Comments(0) Diggs(0) Edit
代码: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL Read More
posted @ 2021-09-26 16:13 A-inspire Views(11) Comments(0) Diggs(0) Edit
思路 思路: 遍历矩阵,第一行上面:前后相加。第一列上面:上下相加。中间:比较上下后加上当前值。 代码 class Solution { public: int minPathSum(vector<vector<int>>& grid) { for(int i = 0;i<grid.size();i Read More
posted @ 2021-09-26 16:09 A-inspire Views(15) Comments(0) Diggs(0) Edit
思路 1 通过数组下标进行计算 先沿着竖直方向中心线翻转+再沿着主对角线翻转 代码: class Solution { public: void rotate(vector<vector<int>>& matrix) { int len = matrix.size(); //先进行行以中间线进行翻转 Read More
posted @ 2021-09-26 16:07 A-inspire Views(26) Comments(0) Diggs(0) Edit
思路 乘积 = 当前数左边的乘积 * 当前数右边的乘积 代码 class Solution { public: vector<int> productExceptSelf(vector<int>& nums) { vector<int>result(nums.size(),0); int k = 1 Read More
posted @ 2021-09-26 16:05 A-inspire Views(12) Comments(0) Diggs(0) Edit
思路 1、判断左子树是否为空,若为空则直接往右走,若不为空则22、将当前节点root的右子树接到当前root节点的左孩子节点的最右下边的孩子节点3、将当前节点root的左子树接到右子树上,并将左节点置为NULL。 /** * Definition for a binary tree node. * Read More
posted @ 2021-09-26 16:04 A-inspire Views(19) Comments(0) Diggs(0) Edit
思路 代码: class Solution { public: vector<int> countBits(int num) { vector<int>result(num+1); result[0] = 0; for(int i =1;i<=num;i++) { if(i%2 == 0){ res Read More
posted @ 2021-09-26 16:03 A-inspire Views(23) Comments(0) Diggs(0) Edit
上一页 1 2 3 4 5 6 7 8 9 10 ··· 25 下一页