3. Longest Substring Without Repeating Characters

LJM·2023년 1월 3일
0

LeetCode

목록 보기
8/10
class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        
        unordered_map<char, int> hashmap;
        
        int count = 0;
        int max = 0;
        
        int start = 0;
        int end = 0;
        
        while(start < s.length())
        {
            hashmap[s[start]]++;
            
            while(hashmap[s[start]] > 1)
            {
                hashmap[s[end]]--;                    
                end++;
            }
            
            count = start - end + 1;
            
            if(count > max)
                max = count;
            
            start++;
        }
        
        return max;
        
    }
};
profile
게임개발자 백엔드개발자

0개의 댓글