Top 150 Interview簡単

Longest Substring Without Repeating Characters

Detailed guide and Python implementation for the 'Longest Substring Without Repeating Characters' problem.

問題提起

簡単

Given a string s, find the length of the longest substring without repeating characters.

Write a function lengthOfLongestSubstring(s: str) -> int.

制約
  • 0 <= len(s) <= 5 * 10^4
  • s consists of English letters, digits, symbols, and spaces

Example 1
Input
s = "abcabcbb"
Output
3
Explanation

The answer is "abc", with a length of 3.

Example 2
Input
s = "bbbbb"
Output
1
Explanation

The answer is "b", with a length of 1.

Example 3
Input
s = "pwwkew"
Output
3
Explanation

The answer is "wke", with a length of 3. Note that "pwke" is a subsequence, not a substring.

Need a Hint?
Consider using Sliding Window-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

解決する準備はできましたか?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

エディタで開く
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

推奨される Python リソース

関連するインタラクティブなチュートリアル、チートシート、コード比較で知識を深めてください。