![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
困死了1111
这个作者很懒,什么都没留下…
展开
-
week8
从集合的角度来考虑dp问题寻找某一状态来代表一类东西dp考虑方式:1.状态表示 f[i] :(1)集合:所有以i结尾的子段(2) 属性max/min/数量。 2.状态计算——集合的划分。f[i]=max(0,f[i-1])+nums[i];class Solution {public: int maxSubArray(vector<int>& nums) { int res=INT_MIN,...原创 2020-09-03 18:29:04 · 119 阅读 · 0 评论 -
week7
class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { unordered_map<int,int>hash; for(int i=0;i<nums.size();i++) { if(hash.count(target-nums[i])) .原创 2020-09-03 13:50:25 · 69 阅读 · 0 评论 -
week6
class Solution {public: vector<int> twoSum(vector<int>& numbers, int target) { for(int j=0,i=numbers.size()-1;j<numbers.size();j++) { while(i-1>j &&numbers[i-1]+numbers[j]>=target) i--; .原创 2020-09-01 16:55:27 · 74 阅读 · 0 评论 -
week5
百分之80 的暴搜题目是要回溯(恢复先前状态)class Solution {public: string chars[8]={"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; vector<string> letterCombinations(string digits) { if(digits.empty()) return vector<string>(); vec原创 2020-09-01 15:11:15 · 103 阅读 · 0 评论 -
week4
class Solution {public: string countAndSay(int n) { string s="1"; for(int i=2;i<=n;i++) { string ns; for(int k=0;k<s.length();) { int j=k+1; while(s[j]=.原创 2020-08-31 00:15:30 · 88 阅读 · 0 评论 -
week3
bool isValidBST(TreeNode* root) { return dfs(root,INT_MIN,INT_MAX); } bool dfs(TreeNode*root,long long MINV,long long MAXV) { if(!root) return true; if(root->val<MINV || root->val > MAXV) return false; .原创 2020-08-29 20:58:18 · 78 阅读 · 0 评论 -
week1
二分的流程1.确定二分的边界2.编写二分的代码框架3.设计一个check(性质)4.判断一下区间如何更新5.如果更新方式写的是l=mid,r=mid-1 ,那么算mid的是时候+1;6 绿色:(check)R=M,L=M+1 MID=(L+R)/2红色:(check)L=M,R=M-1MID=(L+R+1)/2 int mySqrt(int x) { int l=0,r=x; while(l<r) { .原创 2020-08-29 01:01:44 · 136 阅读 · 0 评论 -
week2
ListNode* removeNthFromEnd(ListNode* head, int n) { ListNode *dummy=new ListNode(-1); dummy->next=head; ListNode *first=dummy; ListNode *second=dummy; for(int i=0;i<n;i++) first=first->next; .原创 2020-08-26 23:21:44 · 63 阅读 · 0 评论