File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed
c-sharp/Problems/arrays-and-hashing Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 15
15
* • The letter 'b' appears on the indexes 1 and 4.
16
16
* • The letter 'c' appears on the indexes 2, 3 and 7.
17
17
* • The letter 'z' appears on the index 8.
18
- * • 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.
19
- *
18
+ * • The letter 'c' is the first letter to appear twice,
19
+ * because out of all the letters the index of its second occurrence is the smallest.
20
+ *
20
21
* Example 2:
21
22
* Input: s = "abcdd"
22
23
* Output: "d"
23
24
* Explanation: The only letter that appears twice is 'd' so we return 'd'.
24
- *
25
- *
25
+ *
26
26
* Constraints:
27
27
* • 2 <= s.length <= 100
28
28
* • s consists of lowercase English letters.
29
29
* • s has at least one repeated letter.
30
- *
30
+ *
31
31
* Hint 1: Iterate through the string from left to right.
32
32
* Keep track of the elements you have already seen in a set.
33
- *
33
+ *
34
34
* Hint 2: If the current element is already in the set, return that element.
35
35
**
36
36
* https://leetcode.com/problems/first-letter-to-appear-twice/
@@ -44,7 +44,7 @@ public class FirstLetterToAppearTwice
44
44
{
45
45
public char RepeatedCharacter ( string s )
46
46
{
47
- HashSet < char > charMap = new ( ) ;
47
+ HashSet < char > charMap = [ ] ;
48
48
49
49
foreach ( char c in s )
50
50
{
You can’t perform that action at this time.
0 commit comments