Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jiang feng
leetcode-Python
Commits
fa55a3b5
Commit
fa55a3b5
authored
Mar 18, 2026
by
jiang feng
Browse files
Upload New File
parent
e7bb2caf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
0 deletions
+28
-0
01/03.py
01/03.py
+28
-0
No files found.
01/03.py
0 → 100644
View file @
fa55a3b5
'''
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
'''
class
Solution
(
object
):
def
lengthOfLongestSubstring
(
self
,
s
):
"""
:type s: str
:rtype: int
"""
mapSet
=
{}
start
,
result
=
0
,
0
for
end
in
range
(
len
(
s
)):
if
s
[
end
]
in
mapSet
:
start
=
max
(
mapSet
[
s
[
end
]],
start
)
result
=
max
(
result
,
end
-
start
+
1
)
mapSet
[
s
[
end
]]
=
end
+
1
return
result
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment