Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Solution {
public:
inline int lengthOfLongestSubstring(string s) {
const int maxs = 96;
int pos[maxs];
int ans = 0;
int cur = 0;
int tmp;
int length = s.length();
int flag = length;
memset(pos, -1, sizeof(pos));
for (int i = length - 1; i >= 0; i --)
{
tmp = s[i] - 32;
if (pos[tmp] != -1)
{
if (pos[tmp] > flag) {
cur = flag - i;
ans = max(cur, ans);
} else {
flag = pos[tmp];
cur = flag - i;
}
} else {
cur += 1;
ans = max(cur, ans);
}
pos[tmp] = i;
}
return ans;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.