![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
力扣
记录自己刷题的经历吧
恩嗯
一个正在学习的,普通人
展开
-
打家劫舍(三光)
没啥好说的,嗯,就是那个啥动态规划,对就是动态规划。class Solution {public: int rob(vector<int>& nums) { int n = nums.size(); vector<int> dp(n); dp[0] = nums[0]; dp[1] = max(nums[0],nums[1]); for(int i = 2;i < n;++i)原创 2020-07-23 22:13:44 · 116 阅读 · 0 评论 -
二叉树的中序遍历(递归和非递归)
非递归:在这class Solution {public: vector<int> inorderTraversal(TreeNode* root) { vector<int> vec; stack <TreeNode*> sta; TreeNode* ptr = root; while(NULL != ptr || !sta.empty()) {原创 2020-07-23 21:14:25 · 99 阅读 · 0 评论 -
不同的二叉搜索树
好吧我是懒狗,看到这个题,第一反应就是,递归去做,这个题也没给时间限制,我就试了一下递归。int numTrees(int n){ int sum = 0; if(n == 1 || n == 0) { return 1; } for(int i = 1;i <= n;++i) { sum +=numTrees(i-1) * numTrees(n - i); } return sum;}大概就原创 2020-07-22 23:11:44 · 132 阅读 · 0 评论 -
力扣——两数之和(简单)
#include<iostream>using namespace std;void Sum(int *nums,int target,int len,int &f1,int &f2){ if(NULL == nums)return ; for(int i = 0;i < len;++i) { for(int j = i+1;j < len;++j) { if(nums[i.原创 2020-07-21 22:26:41 · 483 阅读 · 0 评论