Class Solution

java.lang.Object
g1701_1800.s1763_longest_nice_substring.Solution

public class Solution extends Object
1763 - Longest Nice Substring.<p>Easy</p> <p>A string <code>s</code> is <strong>nice</strong> if, for every letter of the alphabet that <code>s</code> contains, it appears <strong>both</strong> in uppercase and lowercase. For example, <code>&quot;abABB&quot;</code> is nice because <code>'A'</code> and <code>'a'</code> appear, and <code>'B'</code> and <code>'b'</code> appear. However, <code>&quot;abA&quot;</code> is not because <code>'b'</code> appears, but <code>'B'</code> does not.</p> <p>Given a string <code>s</code>, return <em>the longest <strong>substring</strong> of <code>s</code> that is <strong>nice</strong>. If there are multiple, return the substring of the <strong>earliest</strong> occurrence. If there are none, return an empty string</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;YazaAay&rdquo;</p> <p><strong>Output:</strong> &ldquo;aAa&rdquo;</p> <p><strong>Explanation:</strong> &ldquo;aAa&rdquo; is a nice string because &lsquo;A/a&rsquo; is the only letter of the alphabet in s, and both &lsquo;A&rsquo; and &lsquo;a&rsquo; appear. &ldquo;aAa&rdquo; is the longest nice substring.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;Bb&rdquo;</p> <p><strong>Output:</strong> &ldquo;Bb&rdquo;</p> <p><strong>Explanation:</strong> &ldquo;Bb&rdquo; is a nice string because both &lsquo;B&rsquo; and &lsquo;b&rsquo; appear. The whole string is a substring.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;c&rdquo;</p> <p><strong>Output:</strong> &quot;&quot;</p> <p><strong>Explanation:</strong> There are no nice substrings.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 100</code></li> <li><code>s</code> consists of uppercase and lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • longestNiceSubstring

      public String longestNiceSubstring(String s)