Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 735 Bytes

longest-substring-without-repeating-characters.md

File metadata and controls

29 lines (22 loc) · 735 Bytes
"""
  Problem Name : Longest Substring Without Repeating Characters
  Problem URL : https://leetcode.com/problems/longest-substring-without-repeating-characters/
  Description :
    Given a string s, find the length of the longest substring without repeating characters.

  Difficulty : Medium
  Language : Python3
  Category : Algorithms
"""

class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        dic = {}
        left = 0
        maxi = 0
        for right, x in enumerate(s):
            if x in dic:
                left = max(left, dic[x])
            dic[x] = right + 1
            maxi = max(maxi, right - left + 1)
        
            
                
                
        return maxi