LincolnZhen
LincolnZhen
全部文章
分类
题解(14)
归档
标签
去牛客网
登录
/
注册
LincolnZhen的博客
全部文章
(共14篇)
题解 | #矩阵的最小路径和#
class Solution { public: /** * * @param matrix int整型vector<vector<>> the matrix * @return int整型 */ int minPat...
C++
2021-09-29
0
274
题解 | #二叉树的最小深度#
/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ class Solution { public: /** * ...
C++
2021-09-28
0
322
题解 | #数组中只出现一次的数(其它数出现k次)#
解法:利用二进制,记录一下每一位上1出现的次数。然后除k,如果余1的话就说明只出现了一次的数这一位是1,然后恢复成十进制。 class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * ...
C++
2021-09-25
0
255
题解 | #重建二叉树#
解法:使用递归重建左右子树即可。与输出二叉树右视图比较相似。结束递归的条件为preStart > pre.size()或者vStart > vEnd;左子树根节点在前序遍历pre中的位置为preStart = preStart + 1,全部左子树位于中序遍历vin[vStart:root...
C++
二叉树
2021-09-25
0
257
题解 | #三个数的最大乘积#
解法:寻找前三大和最小的两个数,最后返回 前三大的乘积 和 最大值*最小的两个数 中的较大值 class Solution { public: /** * 最大乘积 * @param A int整型一维数组 * @param ALen int A数组长度 ...
C++
2021-09-24
0
332
题解 | #求平方根#
注意在计算mid的时候要先将left和right转化成float或者double class Solution { public: /** * * @param x int整型 * @return int整型 */ int sqrt(int...
C++
二分查找
2021-09-24
0
372
题解 | #数组中相加和为0的三元组#
按照规则找数就行 class Solution { public: vector<vector<int> > threeSum(vector<int> &num) { int a, b, c; int i, j; ...
C++
双指针
2021-09-23
0
323
题解 | #最长回文子串#
解法: 动态规划, 状态转移矩阵Matrix[n][n], 以left代表子串开头位置,right代表子串结尾位置, left <= right 如果子串不是回文字符串, Matrix[left][right] = 0,, 如果子串是回文字符串, Matrix[left][right] =...
C++
动态规划
2021-09-22
0
251
题解 | #斐波那契数列#
斐波那契数列的通项公式推导:https://blog.csdn.net/zhouchangyu1221/article/details/104974955。 class Solution { public: int Fibonacci(int n) { if (n == 0)...
C++
2021-09-22
0
181
题解 | #单链表的排序#
/** * struct ListNode { * int val; * struct ListNode *next; * }; */ class Solution { public: /** * * @param head ListNode类...
C++
2021-09-21
0
231
首页
上一页
1
2
下一页
末页