随笔分类 -  刷题总结

力扣题型总结
摘要:class Solution { public: void nextPermutation(vector<int>& nums) { int n=nums.size(); int i=n-2; while(i>=0 && nums[i]>=nums[i+1]){//从后向前,找到第一个降序的,一直升 阅读全文
posted @ 2023-08-09 14:13 Ojalá 阅读(18) 评论(0) 推荐(0)
摘要://分治 class Solution { public: ListNode* mergeTwoLists(ListNode* a,ListNode* b){ ListNode* dummynode=new ListNode(0); ListNode* cur=dummynode; while(a! 阅读全文
posted @ 2023-08-09 00:46 Ojalá 阅读(25) 评论(0) 推荐(0)
摘要:回溯的本质是穷举,穷举所有情况,这里有剪枝,只在有效情况下继续 class Solution { vector<string> res; string str; void backtracking(int left,int right){ if(left<0 || left>right) retur 阅读全文
posted @ 2023-08-06 18:30 Ojalá 阅读(21) 评论(0) 推荐(0)
摘要:class Solution { public: ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) { ListNode* dummynode=new ListNode(0); ListNode* cur=dummynode; whi 阅读全文
posted @ 2023-08-05 17:35 Ojalá 阅读(23) 评论(0) 推荐(0)
摘要:双指针,头尾指针每次移动较小的那个,保证有取到更大值的可能性 class Solution { public: int maxArea(vector<int>& height) { int size=height.size(); int i=0,j=size-1; int maxval=0; whi 阅读全文
posted @ 2023-08-05 10:31 Ojalá 阅读(21) 评论(0) 推荐(0)
摘要:class Solution { public: bool isMatch(string s, string p) { int m=s.size()+1;int n=p.size()+1; vector<vector<bool>> dp(m,vector<bool>(n,false)); dp[0] 阅读全文
posted @ 2023-08-05 01:37 Ojalá 阅读(28) 评论(0) 推荐(0)