File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed
problem_1935_maximum_number_of_words_you_can_type Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -635,6 +635,7 @@ pub mod problem_1880_check_if_word_equals_summation_of_two_words;
635
635
pub mod problem_1903_largest_odd_number_in_string;
636
636
pub mod problem_1920_build_array_from_permutation;
637
637
pub mod problem_1929_concatenation_of_array;
638
+ pub mod problem_1935_maximum_number_of_words_you_can_type;
638
639
pub mod problem_1961_check_if_string_is_a_prefix_of_array;
639
640
pub mod problem_1962_remove_stones_to_minimize_the_total;
640
641
pub mod problem_2032_two_out_of_three;
Original file line number Diff line number Diff line change
1
+ pub struct Solution ;
2
+
3
+ impl Solution {
4
+ pub fn can_be_typed_words ( text : String , broken_letters : String ) -> i32 {
5
+ let mut broken = [ false ; 26 ] ;
6
+ for byte in broken_letters. bytes ( ) {
7
+ broken[ ( byte - b'a' ) as usize ] = true ;
8
+ }
9
+ text. split ( ' ' )
10
+ . filter ( |s| !s. bytes ( ) . any ( |x| broken[ ( x - b'a' ) as usize ] ) )
11
+ . count ( ) as _
12
+ }
13
+ }
14
+
15
+ impl super :: Solution for Solution {
16
+ fn can_be_typed_words ( text : String , broken_letters : String ) -> i32 {
17
+ Self :: can_be_typed_words ( text, broken_letters)
18
+ }
19
+ }
20
+
21
+ #[ cfg( test) ]
22
+ mod tests {
23
+ #[ test]
24
+ fn test_solution ( ) {
25
+ super :: super :: tests:: run :: < super :: Solution > ( ) ;
26
+ }
27
+ }
Original file line number Diff line number Diff line change
1
+ pub mod iterative;
2
+
3
+ pub trait Solution {
4
+ fn can_be_typed_words ( text : String , broken_letters : String ) -> i32 ;
5
+ }
6
+
7
+ #[ cfg( test) ]
8
+ mod tests {
9
+ use super :: Solution ;
10
+
11
+ pub fn run < S : Solution > ( ) {
12
+ let test_cases = [
13
+ ( ( "hello world" , "ad" ) , 1 ) ,
14
+ ( ( "leet code" , "lt" ) , 1 ) ,
15
+ ( ( "leet code" , "e" ) , 0 ) ,
16
+ ] ;
17
+
18
+ for ( ( text, broken_letters) , expected) in test_cases {
19
+ assert_eq ! (
20
+ S :: can_be_typed_words( text. to_string( ) , broken_letters. to_string( ) ) ,
21
+ expected,
22
+ ) ;
23
+ }
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments