+ 2
Confused
So the result of this is 4 despite it supposed to be 3. Confused as to why it's giving 4. def lengthOfLongestSubstring(s): Map = [] for char in s: if char in Map: pass else: Map.append(char) return len(Map) Map.clear() print(lengthOfLongestSubstring('pwwkew'))
4 Answers
+ 3
from pwkew pwke get appended to Map so len returns 4
instead of pass you should write Map=[] if you are expecting output 3
+ 1
But I thought len() started at zero shoudn't it have been 3 anyway? Did it double count or something like that?
+ 1
Length is always starting with one.
0
(my answer was not really the best...)