From ebb8ca896fcb1bf4e7f74c7fd8d705e30963c16b Mon Sep 17 00:00:00 2001 From: JungHwan Date: Mon, 22 Jul 2024 00:35:16 +0900 Subject: [PATCH] 7/22 1Q --- .../NeetCode_LongestSubstringWithoutDuplicates.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 JungHwan/Day21/NeetCode_LongestSubstringWithoutDuplicates.py diff --git a/JungHwan/Day21/NeetCode_LongestSubstringWithoutDuplicates.py b/JungHwan/Day21/NeetCode_LongestSubstringWithoutDuplicates.py new file mode 100644 index 0000000..15de090 --- /dev/null +++ b/JungHwan/Day21/NeetCode_LongestSubstringWithoutDuplicates.py @@ -0,0 +1,13 @@ +class Solution: + def lengthOfLongestSubstring(self, s: str) -> int: + l, r = 0, 0 + maxl = 0 + while r < len(s): + for i in range(l, r): + if s[r] == s[i]: #found duplicate + l = r = i + 1 + break + #duplicate not found + maxl = max(maxl, r - l + 1) + r += 1 + return maxl \ No newline at end of file