#1763
Longest Nice Substring
pupil · 395 · lc easy +24 · premium · verified · 63.8% accepted · 1,510 likes · top 66%
Description
A string s is nice if every letter that appears in it is present in both uppercase and lowercase forms. Given s, return the longest nice substring. On ties return the earliest one. Return an empty string if no nice substring exists.
Example 1:
Input: s = "YazaAay"
Output: "aAa"
Explanation: "aAa" is a nice string because 'A/a' is the only letter of the alphabet in s, and both 'A' and 'a' appear.
"aAa" is the longest nice substring.
Example 2:
Input: s = "Bb"
Output: "Bb"
Explanation: "Bb" is a nice string because both 'B' and 'b' appear. The whole string is a substring.
Example 3:
Input: s = "c"
Output: ""
Explanation: There are no nice substrings.
Code
1
2
3