leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1371.cpp (692B)
0 class Solution {
1 static const uint8_t map[27];
3 public:
4 int findTheLongestSubstring(const string &s) {
5 static int um[1 << 5];
6 memset(um, 0xFF, sizeof(um));
7 int res = 0, crnt = 0;
8 for (int i = 0; i < s.size(); i++) {
9 crnt ^= (1 << map[s[i] & 0x1F]) >> 1;
10 if (!crnt)
11 res = max(res, i + 1);
12 else if (um[crnt] == -1)
13 um[crnt] = i;
14 else
15 res = max(res, i - um[crnt]);
16 }
17 return res;
18 }
19 };
21 const uint8_t Solution::map[27] = {0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0,
22 0, 4, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0};