Skip to content

Commit

Permalink
3. Longest Substring Without Repeating Characters
Browse files Browse the repository at this point in the history
  • Loading branch information
shashank-indukuri authored Sep 21, 2021
1 parent dce31c4 commit 2c54a8c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions longestSubString.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Given a string s, find the length of the longest substring without repeating characters.



# Example 1:

# Input: s = "abcabcbb"
# Output: 3
# Explanation: The answer is "abc", with the length of 3.
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
queue = []
queueDict = {}
maxLen = 0

for char in s:
while char in queueDict:
k = queue.pop(0)
queueDict.pop(k)
queue.append(char)
queueDict[char] = char
queueLen = len(queue)
maxLen = max(maxLen, queueLen)

return maxLen

0 comments on commit 2c54a8c

Please sign in to comment.