File tree 3 files changed +42
-2
lines changed
3 files changed +42
-2
lines changed Original file line number Diff line number Diff line change 1
- mod p1800 ;
1
+ mod p1790 ;
2
2
3
3
pub fn main ( ) {
4
- p1800 :: run ( ) ;
4
+ p1790 :: run ( ) ;
5
5
}
Original file line number Diff line number Diff line change
1
+ use std:: collections:: HashSet ;
2
+
3
+ pub fn run ( ) {
4
+ for i in [
5
+ ( "bank" , "kanb" ) ,
6
+ ( "attack" , "defend" ) ,
7
+ ( "kelb" , "kelb" ) ,
8
+ ( "aa" , "ac" ) ,
9
+ ( "aa" , "bb" )
10
+ ] {
11
+ println ! ( "{}" , are_almost_equal( i. 0 . to_string( ) , i. 1 . to_string( ) ) ) ;
12
+ }
13
+ }
14
+
15
+ pub fn are_almost_equal ( s1 : String , s2 : String ) -> bool {
16
+ let mut s1 = s1. chars ( ) ;
17
+ let mut s2 = s2. chars ( ) ;
18
+
19
+ let mut differences_a = HashSet :: new ( ) ;
20
+ let mut differences_b = HashSet :: new ( ) ;
21
+
22
+ let mut count = 0 ;
23
+
24
+ while let Some ( a) = s1. next ( ) {
25
+ let b = s2. next ( ) . unwrap ( ) ;
26
+
27
+ if a != b {
28
+ differences_a. insert ( a) ;
29
+ differences_b. insert ( b) ;
30
+
31
+ count += 1 ;
32
+ if count >= 3 {
33
+ return false ;
34
+ }
35
+ }
36
+ }
37
+
38
+ ( differences_a == differences_b) &&
39
+ ( ( count == 0 ) || ( count == 2 ) )
40
+ }
You can’t perform that action at this time.
0 commit comments