Skip to content

Commit ccb573f

Browse files
authored
Create 3442. Maximum Difference Between Even and Odd Frequency I (#813)
2 parents 03aaf46 + f695ebf commit ccb573f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int maxDifference(string s) {
4+
vector<int> freq(26,0);
5+
int n = s.length();
6+
for(auto it: s){
7+
freq[it - 'a']++;
8+
}
9+
int oddMax = INT_MIN, evenMin = INT_MAX;
10+
for(auto it:freq){
11+
if(it){
12+
it%2?oddMax = max(oddMax, it):evenMin = min(evenMin, it);
13+
}
14+
}
15+
return oddMax - evenMin;
16+
}
17+
};

0 commit comments

Comments
 (0)