diff --git a/test008.cpp b/test008.cpp new file mode 100644 index 0000000..88e7aa9 --- /dev/null +++ b/test008.cpp @@ -0,0 +1,17 @@ +class Solution { +public: + int lengthOfLongestSubstring(string s) { + int n = s.length(); + int ret = 0; + unordered_map count; + int l = 0; + for(int r = 0; r < n; r++){ + count[s[r]]++; + while(count[s[r]] >= 2){ + count[s[l++]]--; + } + ret = max(ret, r - l + 1); + } + return ret; + } +}; \ No newline at end of file