Skip to content

Commit

Permalink
leetcode max len substring with two occurrences
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatelmas committed Mar 25, 2024
1 parent bcd28a4 commit 161df4d
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from collections import Counter


class Solution:
def maximumLengthSubstring(self, s: str) -> int:
l, m = len(s), 0
for i in range(l, 0, -1):
for j in range(l - i + 1):
if i <= m:
continue
c = Counter(s[j : j + i])
if c.most_common(1)[0][1] <= 2:
m = max(m, i)
return m

0 comments on commit 161df4d

Please sign in to comment.