150 principais entrevistasFácil

Substring mais longa sem repetição de caracteres

Guia detalhado e implementação de Python para o problema 'Substring mais longa sem caracteres repetidos'.

Declaração do problema

Fácil

Dada uma string s, encontre o comprimento da substring mais longa sem repetir caracteres.

Escreva uma função lengthOfLongestSubstring(s: str) -> int.

Restrições
  • 0 <= len(s) <= 5 * 10^4
  • s consists of English letters, digits, symbols, and spaces

Exemplos

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?
Considere usar estruturas de dados específicas da janela deslizante, como conjuntos ou heaps.
Edge Cases to Watch
  • Estruturas de entrada vazias
  • Entradas de elemento único
  • Grandes limites numéricos

Pronto para resolver?

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

Abrir no Editor
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

Recursos Python recomendados

Expanda seu conhecimento com tutoriais interativos relacionados, folhas de dicas e comparações de código.