摘要: 题目 1 class Solution { 2 public: 3 vector<int>ans1; 4 vector<int>ans2; 5 bool leafSimilar(TreeNode* root1, TreeNode* root2) { 6 dfs(root1,ans1); 7 dfs( 阅读全文
posted @ 2021-01-13 15:16 Uitachi 阅读(70) 评论(0) 推荐(0)
摘要: 题目 和LeetCode530没什么区别 1 class Solution { 2 public: 3 vector<int>ans; 4 int minDiffInBST(TreeNode* root) { 5 int min = INT_MAX;dfs(root); 6 for(int i = 阅读全文
posted @ 2021-01-12 17:37 Uitachi 阅读(88) 评论(0) 推荐(0)
摘要: 题目 代码 简单递归 1 class Solution { 2 public: 3 TreeNode* searchBST(TreeNode* root, int val) { 4 if(!root) return NULL; 5 TreeNode* p; 6 if(root->val == val 阅读全文
posted @ 2021-01-12 17:18 Uitachi 阅读(72) 评论(0) 推荐(0)
摘要: 题目 纯暴力 1 class Solution { 2 public: 3 vector<int>ans; 4 int findSecondMinimumValue(TreeNode* root) { 5 dfs(root); 6 sort(ans.begin(),ans.end()); 7 int 阅读全文
posted @ 2021-01-12 16:49 Uitachi 阅读(68) 评论(0) 推荐(0)
摘要: 题目 直接暴力 1 class Solution { 2 public: 3 vector<int>ans; 4 bool findTarget(TreeNode* root, int k) { 5 dfs(root); 6 for(int i = 0;i <ans.size();i++) 7 fo 阅读全文
posted @ 2021-01-11 17:00 Uitachi 阅读(73) 评论(0) 推荐(0)
摘要: 2014年斯坦福机器学习课程2-7 课程中主要介绍梯度下降算法找代价函数的最小值。我们知道梯度下降可以找到局部最优, 但不一定是全局最优。但如果convex function(凸函数),可以通过梯度下降找到全局最优解。 此时局部最优对应全局最优。于是恩达老师举了个凸函数的例子,弓形的曲面。但并没有具 阅读全文
posted @ 2021-01-11 16:28 Uitachi 阅读(177) 评论(0) 推荐(0)
摘要: 题目 1 class Solution { 2 public: 3 vector<double>ans; 4 vector<double> averageOfLevels(TreeNode* root) { 5 if(!root) return ans; 6 queue<TreeNode*>q; 7 阅读全文
posted @ 2021-01-11 16:08 Uitachi 阅读(87) 评论(0) 推荐(0)
摘要: 题目 1 class Solution { 2 public: 3 TreeNode* mergeTrees(TreeNode* t1, TreeNode* t2) { 4 if(!t1 && !t2) return NULL; 5 if(t1 == NULL&& t2 != NULL) retur 阅读全文
posted @ 2021-01-11 11:53 Uitachi 阅读(72) 评论(0) 推荐(0)
摘要: 题目 1 class Solution { 2 public: 3 vector<int>ans; 4 vector<int> postorder(Node* root) { 5 dfs(root); 6 return ans; 7 } 8 void dfs(Node* root){ 9 if(ro 阅读全文
posted @ 2021-01-10 18:12 Uitachi 阅读(81) 评论(0) 推荐(0)
摘要: 题目 法一、递归 1 class Solution { 2 public: 3 vector<int>ans; 4 void dfs(Node* root){ 5 if(root!=NULL){ 6 ans.push_back(root->val); 7 for(int i = 0;i < root 阅读全文
posted @ 2021-01-10 17:56 Uitachi 阅读(79) 评论(0) 推荐(0)