Class Solution
java.lang.Object
g2301_2400.s2351_first_letter_to_appear_twice.Solution
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 = “abccbaacz”</p>
<p><strong>Output:</strong> “c”</p>
<p><strong>Explanation:</strong></p>
<p>The letter ‘a’ appears on the indexes 0, 5 and 6.</p>
<p>The letter ‘b’ appears on the indexes 1 and 4.</p>
<p>The letter ‘c’ appears on the indexes 2, 3 and 7.</p>
<p>The letter ‘z’ appears on the index 8.</p>
<p>The letter ‘c’ 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 = “abcdd”</p>
<p><strong>Output:</strong> “d”</p>
<p><strong>Explanation:</strong></p>
<p>The only letter that appears twice is ‘d’ so we return ‘d’.</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 Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
repeatedCharacter
-