Skip to content

Commit

Permalink
Add solution for Longest Nice Substring
Browse files Browse the repository at this point in the history
  • Loading branch information
Blacknahil committed Feb 29, 2024
1 parent f33ece2 commit df80c8a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions camp1/week3/leetcode/longest-nice-substring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Solution:
def longestNiceSubstring(self, s: str) -> str:
unique=set(s)

for i,char in enumerate(s):
if char.swapcase() not in unique:
return max(self.longestNiceSubstring(s[:i]),self.longestNiceSubstring(s[i+1:]),key=len)
return s

0 comments on commit df80c8a

Please sign in to comment.