会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
Uitachi
fresh coder
博客园
首页
新随笔
联系
订阅
管理
上一页
1
···
13
14
15
16
17
18
19
下一页
2021年1月4日
LeetCode111.二叉树的最小深度
摘要: 题目 深度优先搜索 1 class Solution { 2 public: 3 int minDepth(TreeNode* root) { 4 if(root == NULL) return 0; 5 if(root->left == NULL) return minDepth(root->ri
阅读全文
posted @ 2021-01-04 11:19 Uitachi
阅读(101)
评论(0)
推荐(0)
2021年1月2日
LeetCode110.平衡二叉树
摘要: 题目 1 class Solution { 2 public: 3 bool isBalanced(TreeNode* root) { 4 if(root == NULL) return true; 5 return abs(height(root->left)-height(root->right
阅读全文
posted @ 2021-01-02 17:41 Uitachi
阅读(82)
评论(0)
推荐(0)
LeetCode108.有序数组转二叉搜索树
摘要: 题目 1 class Solution { 2 public: 3 TreeNode* sortedArrayToBST(vector<int>& nums) { 4 if(nums.size() == 0) return NULL; 5 return build_BST(nums,0,nums.s
阅读全文
posted @ 2021-01-02 17:18 Uitachi
阅读(67)
评论(0)
推荐(0)
LeetCode107.二叉树的层次遍历II
摘要: 题目 1 class Solution { 2 public: 3 vector<vector<int>> levelOrderBottom(TreeNode* root) { 4 auto levelOrder = vector<vector<int>> (); 5 if(root == NULL
阅读全文
posted @ 2021-01-02 16:34 Uitachi
阅读(68)
评论(0)
推荐(0)
LeetCode104.二叉树的最大深度
摘要: 题目 1 class Solution { 2 public: 3 int maxDepth(TreeNode* root) { 4 if(root == NULL) return 0; 5 //return maxDepth(root->left) > maxDepth(root->right)
阅读全文
posted @ 2021-01-02 15:49 Uitachi
阅读(67)
评论(0)
推荐(0)
Leetcode101.对称二叉树
摘要: 题目 1 class Solution { 2 public: 3 4 bool isSymmetric(TreeNode* root) { 5 return check(root,root); 6 } 7 bool check(TreeNode* p,TreeNode* q) { 8 if(!p
阅读全文
posted @ 2021-01-02 15:05 Uitachi
阅读(75)
评论(0)
推荐(0)
Leetcode100.相同的树
摘要: 题目 1 class Solution { 2 public: 3 bool isSameTree(TreeNode* p, TreeNode* q) { 4 if(p == NULL && q == NULL){ 5 return true; 6 }else if(p == NULL || q =
阅读全文
posted @ 2021-01-02 11:05 Uitachi
阅读(69)
评论(0)
推荐(0)
Leetcode100.相同的树
摘要: 题目描述 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode() : val(0),
阅读全文
posted @ 2021-01-02 10:16 Uitachi
阅读(83)
评论(0)
推荐(0)
2020年9月5日
Leetcode53. 最大子序列和
摘要: 问题 给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。 代码 贪心算法 核心思想就是检查之前 i-1 的元素和,如果小于零就舍弃——对应下面第六行代码 1 class Solution { 2 public: 3 int maxSubArray(
阅读全文
posted @ 2020-09-05 17:28 Uitachi
阅读(114)
评论(0)
推荐(0)
2020年8月29日
Leetcode35. 搜索插入位置
摘要: 问题 水题 给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。 你可以假设数组中无重复元素。 代码 自己写麻烦了,时间复杂度不如标答快! 1 class Solution { 2 public: 3 int searchInser
阅读全文
posted @ 2020-08-29 17:50 Uitachi
阅读(169)
评论(0)
推荐(0)
上一页
1
···
13
14
15
16
17
18
19
下一页
公告