2351. First Letter to Appear Twice Easy

@problem@discussion
#Hash Table#String#Counting



1/**
2 * [2351] First Letter to Appear Twice
3 *
4 * Given a string s consisting of lowercase English letters, return the first letter to appear twice.
5 * Note:
6 * 
7 * 	A letter a appears twice before another letter b if the second occurrence of a is before the second occurrence of b.
8 * 	s will contain at least one letter that appears twice.
9 * 
10 *  
11 * Example 1:
12 * 
13 * Input: s = "abccbaacz"
14 * Output: "c"
15 * Explanation:
16 * The letter 'a' appears on the indexes 0, 5 and 6.
17 * The letter 'b' appears on the indexes 1 and 4.
18 * The letter 'c' appears on the indexes 2, 3 and 7.
19 * The letter 'z' appears on the index 8.
20 * 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.
21 * 
22 * Example 2:
23 * 
24 * Input: s = "abcdd"
25 * Output: "d"
26 * Explanation:
27 * The only letter that appears twice is 'd' so we return 'd'.
28 * 
29 *  
30 * Constraints:
31 * 
32 * 	2 <= s.length <= 100
33 * 	s consists of lowercase English letters.
34 * 	s has at least one repeated letter.
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/first-letter-to-appear-twice/
40// discuss: https://leetcode.com/problems/first-letter-to-appear-twice/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn repeated_character(s: String) -> char {
46        '0'
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_2351() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.