|
| 1 | +<p>Given a string <code>s</code> consisting of lowercase English letters, return <em>the first letter to appear <strong>twice</strong></em>.</p> |
| 2 | + |
| 3 | +<p><strong>Note</strong>:</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <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> |
| 7 | + <li><code>s</code> will contain at least one letter that appears twice.</li> |
| 8 | +</ul> |
| 9 | + |
| 10 | +<p> </p> |
| 11 | +<p><strong class="example">Example 1:</strong></p> |
| 12 | + |
| 13 | +<pre> |
| 14 | +<strong>Input:</strong> s = "abccbaacz" |
| 15 | +<strong>Output:</strong> "c" |
| 16 | +<strong>Explanation:</strong> |
| 17 | +The letter 'a' appears on the indexes 0, 5 and 6. |
| 18 | +The letter 'b' appears on the indexes 1 and 4. |
| 19 | +The letter 'c' appears on the indexes 2, 3 and 7. |
| 20 | +The letter 'z' appears on the index 8. |
| 21 | +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. |
| 22 | +</pre> |
| 23 | + |
| 24 | +<p><strong class="example">Example 2:</strong></p> |
| 25 | + |
| 26 | +<pre> |
| 27 | +<strong>Input:</strong> s = "abcdd" |
| 28 | +<strong>Output:</strong> "d" |
| 29 | +<strong>Explanation:</strong> |
| 30 | +The only letter that appears twice is 'd' so we return 'd'. |
| 31 | +</pre> |
| 32 | + |
| 33 | +<p> </p> |
| 34 | +<p><strong>Constraints:</strong></p> |
| 35 | + |
| 36 | +<ul> |
| 37 | + <li><code>2 <= s.length <= 100</code></li> |
| 38 | + <li><code>s</code> consists of lowercase English letters.</li> |
| 39 | + <li><code>s</code> has at least one repeated letter.</li> |
| 40 | +</ul> |
0 commit comments