We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3493a20 commit 13d728cCopy full SHA for 13d728c
scripts/algorithms/F/Find Longest Awesome Substring/Find Longest Awesome Substring.cpp
@@ -1,29 +1,30 @@
1
+// Runtime: 403 ms (Top 40.21%) | Memory: 10.8 MB (Top 68.53%)
2
class Solution {
3
public:
4
int longestAwesome(string s) {
5
unordered_map<int,int> map;
6
int mask = 0, maxL = 0;
7
map[mask] = -1;
-
8
+
9
for(int i=0; i<s.size(); ++i){
10
int ch = s[i]-'0';
11
mask^= (1<<ch);
12
13
if(map.find(mask) != map.end()){
14
maxL = max(maxL, i-map[mask]);
15
}
16
17
for(int x=0; x<=9; ++x){
18
int newMask = mask^(1<<x);
19
if(map.find(newMask) != map.end()){
20
maxL = max(maxL, i-map[newMask]);
21
22
23
24
if(map.find(mask) == map.end()){
25
map[mask] = i;
26
27
28
return maxL;
29
-};
30
+};
0 commit comments