File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
longest-substring-without-repeating-characters Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 1+ """
2+ Blind75 - length of longest substring without repeating characters
3+ https://leetcode.com/problems/longest-substring-without-repeating-characters/
4+ ์๊ฐ๋ณต์ก๋ : O(n)
5+ ๊ณต๊ฐ๋ณต์ก๋ : O(min(m, n)) (๋ฌธ์ ์งํฉ char_index_map์ ํฌ๊ธฐ, ์ต๋๋ n = len(s))
6+ ํ์ด : ์ฌ๋ผ์ด๋ฉ ์๋์ฐ ๊ธฐ๋ฒ์ ์ฌ์ฉํ ๋ฌธ์์ด ์ํ
7+ """
8+
9+
110class Solution :
211 def lengthOfLongestSubstring (self , s : str ) -> int :
3-
12+ max_count = 0
13+ start = 0
14+ char_index_map = {}
15+
16+ for i , char in enumerate (s ):
17+ if char in char_index_map and char_index_map [char ] >= start :
18+ start = char_index_map [char ] + 1
19+ char_index_map [char ] = i
20+ else :
21+ char_index_map [char ] = i
22+ max_count = max (max_count , i - start + 1 )
423
24+ return max_count
25+
You canโt perform that action at this time.
0 commit comments