Could you please tell what is wrong with my code? I am trying to solve the following problem: "Given a string s, find the length of the longest substring without repeating characters."
Example:
Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
My code is as follows:
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
count=[0]*len(s);
for i in range(0,len(s)):
for j in range(1,len(s)-i):
if s[i]!=s[i+j]:
count[i]=count[i]+1;
else:
break;
return max(count);
It returns 4, although the answer is 3.