java.lang.Object
g2301_2400.s2351_first_letter_to_appear_twice.Solution

public class Solution extends Object
2351 - First Letter to Appear Twice.<p>Easy</p> <p>Given a string <code>s</code> consisting of lowercase English letters, return <em>the first letter to appear <strong>twice</strong></em>.</p> <p><strong>Note</strong>:</p> <ul> <li>A letter <code>a</code> appears twice before another letter <code>b</code> if the <strong>second</strong> occurrence of <code>a</code> is before the <strong>second</strong> occurrence of <code>b</code>.</li> <li><code>s</code> will contain at least one letter that appears twice.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;abccbaacz&rdquo;</p> <p><strong>Output:</strong> &ldquo;c&rdquo;</p> <p><strong>Explanation:</strong></p> <p>The letter &lsquo;a&rsquo; appears on the indexes 0, 5 and 6.</p> <p>The letter &lsquo;b&rsquo; appears on the indexes 1 and 4.</p> <p>The letter &lsquo;c&rsquo; appears on the indexes 2, 3 and 7.</p> <p>The letter &lsquo;z&rsquo; appears on the index 8.</p> <p>The letter &lsquo;c&rsquo; is the first letter to appear twice, because out of all the letters the index of its second occurrence is the smallest.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;abcdd&rdquo;</p> <p><strong>Output:</strong> &ldquo;d&rdquo;</p> <p><strong>Explanation:</strong></p> <p>The only letter that appears twice is &lsquo;d&rsquo; so we return &lsquo;d&rsquo;.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= s.length <= 100</code></li> <li><code>s</code> consists of lowercase English letters.</li> <li><code>s</code> has at least one repeated letter.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • repeatedCharacter

      public char repeatedCharacter(String s)