1763. Longest Nice Substring
On This Page
class Solution:
def longestNiceSubstring(self, s: str) -> str:
n = len(s)
res = ''
for i in range(n):
lower = upper = 0
for j in range(i, n):
if s[j].islower():
lower |= 1 << (ord(s[j]) - ord('a'))
else:
upper |= 1 << (ord(s[j]) - ord('A'))
if lower == upper and len(res) < j - i + 1:
res = s[i : j + 1]
return res