Skip to content

Commit 13d728c

Browse files
committed
Runtime: 403 ms (Top 40.21%) | Memory: 10.8 MB (Top 68.53%)
1 parent 3493a20 commit 13d728c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1+
// Runtime: 403 ms (Top 40.21%) | Memory: 10.8 MB (Top 68.53%)
12
class Solution {
23
public:
34
int longestAwesome(string s) {
45
unordered_map<int,int> map;
56
int mask = 0, maxL = 0;
67
map[mask] = -1;
7-
8+
89
for(int i=0; i<s.size(); ++i){
910
int ch = s[i]-'0';
1011
mask^= (1<<ch);
11-
12+
1213
if(map.find(mask) != map.end()){
1314
maxL = max(maxL, i-map[mask]);
1415
}
15-
16+
1617
for(int x=0; x<=9; ++x){
1718
int newMask = mask^(1<<x);
1819
if(map.find(newMask) != map.end()){
1920
maxL = max(maxL, i-map[newMask]);
2021
}
2122
}
22-
23+
2324
if(map.find(mask) == map.end()){
2425
map[mask] = i;
2526
}
2627
}
2728
return maxL;
2829
}
29-
};
30+
};

0 commit comments

Comments
 (0)