远神_
远神_
全部文章
分类
题解(29)
归档
标签
去牛客网
登录
/
注册
远神_的博客
全部文章
(共29篇)
题解 | #平衡二叉树#
非递归方式判断平衡二叉树 class Solution { public: bool hasNoChildren(TreeNode* node) { if (!node->left && !node->right) retu...
2021-07-26
0
396
题解 | #判断二叉树是否对称#
递归 class Solution { public: //递归 bool isSymmetric(TreeNode* root) { // write code here if(!root) return true; return i...
2021-07-26
0
343
题解 | #最大数#
将数字转成字符串,然后对字符串按指定规则排序 指定规则:a+b>b+a,则a排在b前面 class Solution { public: static bool cmp(string a, string b){ return a+b > b+a; } ...
2021-07-26
0
352
题解 | #合并区间#
闭区间的右部分,不断和后面的区间右部分比较并合并 class Solution { public: static bool cmp(Interval& a, Interval& b){ return a.start<b.start; } ...
2021-07-26
0
366
题解 | #求二叉树的层序遍历#
广度优先搜索 class Solution { public: vector<vector<int> > levelOrder(TreeNode* root) { // write code here if(!root) return ...
2021-07-26
0
399
题解 | #二叉树根节点到叶子节点和为指定值的路径#
深度优先搜索 class Solution { public: vector<vector<int> > pathSum(TreeNode* root, int sum) { // write code here if(!root) r...
2021-07-26
0
403
题解 | #二叉树根节点到叶子节点和为指定值的路径#
深度优先搜索 class Solution { public: /** * * @param root TreeNode类 * @param sum int整型 * @return int整型vector<vector<>>...
2021-07-26
0
309
题解 | #旋转字符串#
看时间复杂度就知道运行效率不错,其实很简单,通过下标去分隔字符串,如果A的pre和B的pro可以匹配,并且同时B的pre和A的pro可以匹配,那么这个字符串就符合题目所说的要求 class Solution { public: bool solve(string A, string B) {...
2021-07-26
0
305
题解 | #数组中出现次数超过一半的数字#
排序,返回中间坐标位置元素值 class Solution { public: int MoreThanHalfNum_Solution(vector<int> numbers) { //排序,返回中间坐标位置元素值 sort(numbers.be...
2021-07-26
0
325
题解 设计getMin功能的栈
使用两个栈:元素栈和最小栈,最小栈随时记录当前状态栈的最小值元素栈出栈,最小栈也一块出栈;元素栈入栈,最小栈入栈当前栈状态的最小值 class Solution { public: stack<int> s, s_min; vector<int> getMin...
2021-07-26
0
375
首页
上一页
1
2
3
下一页
末页