Skip to content

Commit 6228ccc

Browse files
authored
Update Longest Substring Without Repeating Characters - Leetcode 3.py
1 parent e825369 commit 6228ccc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Longest Substring Without Repeating Characters - Leetcode 3/Longest Substring Without Repeating Characters - Leetcode 3.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Brute Force
2+
def length_of_longest_substring(s: str) -> int:
3+
max_length = 0
4+
5+
for i in range(len(s)):
6+
for j in range(i, len(s)):
7+
if s[j] in s[i:j]: # Check if the character already appeared in the substring
8+
break
9+
max_length = max(max_length, j - i + 1)
10+
11+
return max_length
12+
# Time: O(n^3)
13+
# Space: O(n)
14+
115
class Solution:
216
def lengthOfLongestSubstring(self, s: str) -> int:
317
l = 0

0 commit comments

Comments
 (0)