摘要:
``` class Solution { public: struct node { int val; int pre; node* next; node(int a,int b,node* c) { val=a; pre=b; next=c; } }; void insert(node* &hea 阅读全文
摘要:
``` class Solution { public: vector calcEquation(vector>& equations, vector& values, vector>& queries) { unordered_set node;//记录所有节点 unordered_map> g; 阅读全文
摘要:
``` class Solution { public: string dfs(string s,int &idx) { string str; while(idx'0'&&s[idx]='0'&&s[idx]<='9') num+=s[idx++]; if(s[idx]=='[') { int c 阅读全文
摘要:
# 快排思想 - 注意,这里是倒序排序,因此应该`while(nums[i].cnt>x);` ``` class Solution { public: struct element { int val,cnt; element(int a,int b) { val=a; cnt=b; } }; v 阅读全文
摘要:
``` class Solution { public: vector countBits(int n) { vector f(n+1); for(int i=1;i>1]+(i&1); return f; } }; ``` 阅读全文
摘要:
## 思路 本题有两点需要解决,如果确定括号的最少删除数量以及删除哪些括号 #### 求出最少删除数量 思路见 LeetCode 22. 括号生成 #### 已知删除数量,删除哪些括号? 直接爆搜,枚举每个括号是否删除 - 如果当前是左括号,枚举是否删除 (删除 0 还是 1 个) - 如果当前是左 阅读全文
摘要:
``` class Solution { public: int findDuplicate(vector& nums) { if(nums.size()<2) return nums[0]; int n=nums.size(); int fast=0,slow=0; do { slow=nums[ 阅读全文
摘要:
``` class Solution { public: void moveZeroes(vector& nums) { if(nums.empty()) return; int n=nums.size(); int idx=n-1; while(idx>=0&&nums[idx]==0) idx- 阅读全文
摘要:
``` class Solution { public: bool searchMatrix(vector>& matrix, int target) { if(matrix.empty()||matrix[0].empty()) return false; int n=matrix.size(), 阅读全文
摘要:
``` class Solution { public: vector maxSlidingWindow(vector& nums, int k) { deque q; vector res; for(int i=0;i=k) q.pop_front(); //插入新元素 while(q.size( 阅读全文