Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- knakul853
- **/
- class Solution {
- public:
- int lengthOfLongestSubstring(string s) {
- int n = (int)s.size();
- vector<int>dict(256, 0);
- int ans = INT_MIN;
- int i=0, j=0;
- while(i < n )
- {
- char c = s[i++];
- dict[c]++;
- while( j < i && dict[c] > 1 )
- {
- dict[s[j]]--;
- j++;
- }
- ans = max( ans, i - j );
- }
- if(ans == INT_MIN) return 0;;
- return ans;
- }
- };
Add Comment
Please, Sign In to add comment