3. Longest Substring Without Repeating Characters無重復字符的最長子串
阿新 • • 發佈:2019-04-05
clas public problem leet style 循環 重復字符 etc spa
網址:https://leetcode.com/problems/longest-substring-without-repeating-characters/
顯然采用sliding window滑動窗口法,輔助以哈希表,判斷字符是否已使用
- 不斷擴充 j,直到 s[j] 已經使用
- 此時,把 i 移動到 j 之前的 s[j] 字符前面,繼續循環
-
class Solution { public: int lengthOfLongestSubstring(string s) { int i = 0, j; int ans = 0; map
3. Longest Substring Without Repeating Characters無重復字符的最長子串