Skip to content

Commit 8069825

Browse files
authored
Merge pull request #77 from InflixOP/patch1
Added 2
2 parents 8303eee + 40f509b commit 8069825

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
int characterReplacement(string s, int k) {
4+
int n=s.length();
5+
int maxi=0;
6+
int maxf=0;
7+
unordered_map<int,int> mp;
8+
int l=0,r=0;
9+
while(r<n){
10+
mp[s[r]-'A']++;
11+
maxf=max(maxf,mp[s[r]-'A']);
12+
if((r-l+1)-maxf>k){
13+
mp[s[l]-'A']--;
14+
maxf=0;
15+
l++;
16+
}else{
17+
maxi=max(maxi,r-l+1);
18+
}
19+
r++;
20+
}
21+
return maxi;
22+
}
23+
};

#930. Binary Subarrays With Sum.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public:
3+
int numSubarraysWithSum(vector<int>& nums, int goal) {
4+
return help(nums,goal)-help(nums,goal-1);
5+
}
6+
int help(vector<int>& nums, int goal){
7+
int l=0,r=0;
8+
int c=0,sum=0;
9+
while(r<nums.size()){
10+
sum+=nums[r];
11+
while(sum>goal&&l<=r){
12+
sum-=nums[l];
13+
l++;
14+
}
15+
c+=(r-l+1);
16+
r++;
17+
}
18+
return c;
19+
}
20+
};

0 commit comments

Comments
 (0)