今際の国の呵呵君
Friday, October 27, 2017
[LeetCode]Longest Substring Without Repeating Characters
Sliding window的做法,动态地维护左右边界,策略如下:
如果当前c没有见过,插入map
如果见过,pop左边界对应的字符直到满足no repeating char的条件
这样的话,对于所有i,我们找到的是最长的以i为右边界的no repeating char的区间。时间复杂度O(n),空间复杂度O(n),代码如下:
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment