In the Leetcode Longest Substring Without Repeating Characters problem solution in Python programming Given a string s, find the length of the longest substring without repeating characters.
Leetcode Longest Substring Without Repeating Characters problem solution in Python programming
class Solution:
# @return an integer
def lengthOfLongestSubstring(self, s):
result = 0
i = 0
ptr = 0
flag = True
while i < len(s):
if flag:
while ptr < len(s):
if s[ptr] not in s[i:ptr]:
ptr += 1
else:
result = max(result, ptr-i)
flag = False
break
if ptr == len(s):
break
if s[i] == s[ptr]:
flag = True
i += 1
return max(result, ptr-i)
Also read,
- Leetcode Longest Substring Without Repeating Characters problem solution in C
- Leetcode Longest Substring Without Repeating Characters problem solution in C++
- Leetcode Longest Substring Without Repeating Characters problem solution in Java
- Leetcode Longest Substring Without Repeating Characters problem solution in C#