File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ use std:: collections:: HashSet ;
2
+
3
+ use crate :: solutions:: Solution ;
4
+
5
+ impl Solution {
6
+ pub fn repeated_character ( s : String ) -> char {
7
+ let mut hash_set = HashSet :: new ( ) ;
8
+
9
+ for c in s. chars ( ) {
10
+ if hash_set. contains ( & c) {
11
+ return c;
12
+ }
13
+
14
+ hash_set. insert ( c) ;
15
+ }
16
+
17
+ unreachable ! ( )
18
+ }
19
+ }
20
+
21
+ #[ test]
22
+ fn test ( ) {
23
+ assert_eq ! ( Solution :: repeated_character( "abccbaacz" . to_owned( ) ) , 'c' ) ;
24
+ assert_eq ! ( Solution :: repeated_character( "abcdd" . to_owned( ) ) , 'd' ) ;
25
+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ pub mod _0020_valid_parentheses;
4
4
pub mod _0026_remove_duplicates_from_sorted_array;
5
5
pub mod _0027_remove_element;
6
6
pub mod _1848_minimum_distance_to_the_target_element;
7
+ pub mod _2351_first_letter_to_appear_twice;
7
8
pub mod _3046_split_the_array;
8
9
pub mod _3151_special_array_i;
9
10
pub mod _3174_clear_digits;
You can’t perform that action at this time.
0 commit comments