随笔分类 - Week6 滑动窗口、双指针、单调队列和单调栈
摘要:1 //数组是连续的 2 class Solution 3 { 4 public: 5 int maxSubarraySumCircular(vector<int>& A) 6 { 7 // 单调队列 8 int n = A.size(); 9 deque<int> q; 10 for(int i
阅读全文
摘要:1 class Solution 2 { 3 public: 4 vector<int> maxSlidingWindow(vector<int>& nums, int k) 5 { 6 vector<int> res; 7 deque<int> q; 8 for(int i = 0;i < num
阅读全文
摘要:1 //自底向上层层叠加 2 class Solution 3 { 4 public: 5 int trap(vector<int>& height) 6 { 7 int res = 0; 8 stack<int> stk; 9 10 for(int i = 0;i < height.size();
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int largestRectangleArea(vector<int>& heights) 5 { 6 int n = heights.size(); 7 vector<int> left(n),right(n); 8 9 //用单
阅读全文
摘要:1 //括号序列合法 <==> 所有前缀和>=0,且总和等于0 2 3 // start当前枚举的这一段的开头 4 // cnt前缀和 5 // (=1 6 // )=-1 7 // 1、cnt<0 => start = i + 1,cnt = 0 8 // 2、cnt>0 => 继续做 9 //
阅读全文
摘要:1 class Solution 2 { 3 public: 4 string minWindow(string s, string t) 5 { 6 unordered_map<char,int> hash; 7 for(auto c : t) hash[c]++; 8 int cnt = has
阅读全文
摘要:1 class Solution 2 { 3 public: 4 vector<int> twoSum(vector<int>& numbers, int target) 5 { 6 int l = 0,r = numbers.size() - 1; 7 while(l < r) 8 { 9 if(
阅读全文
摘要:1 class MinStack 2 { 3 stack<int> data; 4 stack<int> min_data; 5 public: 6 /** initialize your data structure here. */ 7 MinStack() {} 8 9 void push(i
阅读全文
摘要:1 //从nums1后往前依次放置 2 class Solution 3 { 4 public: 5 void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) 6 { 7 int len = m + n - 1; 8 int i
阅读全文
摘要:1 //双指针算法,也就是实现STL中的unique函数 2 class Solution 3 { 4 public: 5 int removeDuplicates(vector<int>& nums) 6 { 7 int n = nums.size(); 8 int j = 0; 9 for(in
阅读全文

浙公网安备 33010602011771号