File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
longest-substring-without-repeating-characters Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -58,3 +58,29 @@ def lengthOfLongestSubstring(self, s: str) -> int:
5858 max_len = max (max_len , right - left + 1 )
5959
6060 return max_len
61+
62+
63+ # HashMap νμ΄
64+ def lengthOfLongestSubstring (s : str ) -> int :
65+ if not s :
66+ return 0
67+
68+ left = 0 # μλμ° μμμ
69+ max_length = 0 # μ΅λ κΈΈμ΄
70+ seen = {} # λ¬Έμμ λ§μ§λ§ λ±μ₯ μμΉλ₯Ό μ μ₯νλ ν΄μλ§΅
71+
72+ for right in range (len (s )):
73+ char = s [right ]
74+
75+ # νμ¬ λ¬Έμκ° μλμ° λ΄μ μ΄λ―Έ μ‘΄μ¬νλ κ²½μ°
76+ if char in seen and seen [char ] >= left :
77+ # μλμ° μμμ μ μ€λ³΅ λ¬Έμ λ€μ μμΉλ‘ μ΄λ
78+ left = seen [char ] + 1
79+
80+ # νμ¬ λ¬Έμμ μμΉ μ
λ°μ΄νΈ
81+ seen [char ] = right
82+
83+ # νμ¬ μλμ° κΈΈμ΄μ μ΅λ κΈΈμ΄ λΉκ΅ ν μ
λ°μ΄νΈ
84+ max_length = max (max_length , right - left + 1 )
85+
86+ return max_length
You canβt perform that action at this time.
0 commit comments