We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 285e2f1 commit 02e2af7Copy full SHA for 02e2af7
2762. Continuous Subarrays
@@ -0,0 +1,22 @@
1
+class Solution {
2
+public:
3
+ long long continuousSubarrays(vector<int>& nums) {
4
+ map<int,int> mp;
5
+ int left,right=0;
6
+ int n=nums.size();
7
+ long long cnt=0;
8
+ while(right<n){
9
+ mp[nums[right]]++;
10
+ while(mp.rbegin()->first-mp.begin()->first>2){
11
+ mp[nums[left]]--;
12
+ if(mp[nums[left]]==0){
13
+ mp.erase(nums[left]);
14
+ }
15
+ left++;
16
17
+ cnt+=right-left+1;
18
+ right++;
19
20
+ return cnt;
21
22
+};
0 commit comments