随笔分类 -  leetcode

摘要:class Solution { public: int largestRectangleArea(vector<int>& h) { vector<int> l=vector<int>(h.size()); vector<int> r=l; stack<int> stk; int res=0; / 阅读全文
posted @ 2023-03-31 16:47 穿过雾的阴霾 阅读(13) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: ListNode* deleteDuplicates(ListNode* head) { ListNode* dummy=new ListNode(-1,nullptr); if(!head||!head->next) return head; Li 阅读全文
posted @ 2023-03-30 13:32 穿过雾的阴霾 阅读(11) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: bool check(vector<int> &nums,int target,int l,int r)//[l,r]区间查找target { while(l<r) { int mid=(l+r+1)>>1; if(target>=nums[mid] 阅读全文
posted @ 2023-03-28 20:48 穿过雾的阴霾 阅读(10) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int fac[10]; void init() { fac[0]=1; fac[1]=1; for(int i=2;i<10;i++) fac[i]=fac[i-1]*i; return; } string str; bool visited[10 阅读全文
posted @ 2023-03-25 16:24 穿过雾的阴霾 阅读(13) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: //f[i]表示跳到i所需的最小步数 int jump(vector<int>& nums) { vector<int> f(10010,0x3f3f3f3f); int n=nums.size(); f[0]=0; for(int i=0;i<n; 阅读全文
posted @ 2023-03-24 14:26 穿过雾的阴霾 阅读(17) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: //f[i]表示下标i是否能跳到 static const int N=3e4+10; bool canJump(vector<int>& nums) { int n=nums.size(); for(int i=0,j=0;i<n;i++)//j记 阅读全文
posted @ 2023-03-24 14:15 穿过雾的阴霾 阅读(13) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int firstMissingPositive(vector<int>& nums) { int n=nums.size(); for(int i=0;i<n;i++) { while(nums[i]>0&&nums[i]<=n&&nums[i]! 阅读全文
posted @ 2023-03-23 16:01 穿过雾的阴霾 阅读(7) 评论(0) 推荐(0) 编辑
摘要:思路 因为找的是字典序升序的下一个排列,因此要尽量保证前面不动,我们从后往前考虑 从后往前找到第一个非降序的位置,然后把这个位置的数字和最小的比它大的数字交换,最后从该位置后整理为升序 这样保证了值变大,且增大的最少 从数组末尾往前找,找到 第一个 位置 j,使得 nums[j] < nums[j 阅读全文
posted @ 2023-03-22 10:57 穿过雾的阴霾 阅读(13) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<string> res; void dfs(int l,int r,int n,string str) { if(r==n&&l==n)//如果左右括号都用完了,说明找到了一个答案 { res.push_back(str); retur 阅读全文
posted @ 2023-03-20 09:43 穿过雾的阴霾 阅读(5) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: ListNode* reverseKGroup(ListNode* head, int k) { ListNode* dummy=new ListNode(-1,head),*tail=dummy; while(tail) { ListNode* t 阅读全文
posted @ 2023-03-19 10:31 穿过雾的阴霾 阅读(14) 评论(0) 推荐(0) 编辑
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : 阅读全文
posted @ 2023-03-18 09:57 穿过雾的阴霾 阅读(9) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: struct cmp { bool operator()(ListNode *a,ListNode *b) { return a->val>b->val; } }; ListNode* mergeKLists(vector<ListNode*>& l 阅读全文
posted @ 2023-03-17 15:51 穿过雾的阴霾 阅读(11) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<vector<int>> fourSum(vector<int>& nums, int target) { vector<vector<int>> ans; long long tmp=target; sort(nums.begin() 阅读全文
posted @ 2023-03-16 21:48 穿过雾的阴霾 阅读(11) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int threeSumClosest(vector<int>& nums, int target) { int n=nums.size(); pair<int,int> res(INT_MAX,0);//分别存储差值,和 sort(nums.beg 阅读全文
posted @ 2023-03-15 11:38 穿过雾的阴霾 阅读(14) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int reverse(int x) { long long res=0; while(x) { int t=x%10; x/=10; res=res*10+t; } if(res<INT_MIN||res>INT_MAX) return 0; re 阅读全文
posted @ 2023-03-13 09:19 穿过雾的阴霾 阅读(10) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示