File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,30 @@ func abs(x int) int {
136
136
}
137
137
```
138
138
139
+ ### ** Rust**
140
+
141
+ ``` rust
142
+ impl Solution {
143
+ pub fn find_closest (words : Vec <String >, word1 : String , word2 : String ) -> i32 {
144
+ let mut res = i32 :: MAX ;
145
+ let mut index1 = - 1 ;
146
+ let mut index2 = - 1 ;
147
+ for (i , word ) in words . iter (). enumerate () {
148
+ let i = i as i32 ;
149
+ if word . eq (& word1 ) {
150
+ index1 = i ;
151
+ } else if word . eq (& word2 ) {
152
+ index2 = i ;
153
+ }
154
+ if index1 != - 1 && index2 != - 1 {
155
+ res = res . min ((index1 - index2 ). abs ());
156
+ }
157
+ }
158
+ res
159
+ }
160
+ }
161
+ ```
162
+
139
163
### ** ...**
140
164
141
165
```
Original file line number Diff line number Diff line change @@ -132,6 +132,30 @@ func abs(x int) int {
132
132
}
133
133
```
134
134
135
+ ### ** Rust**
136
+
137
+ ``` rust
138
+ impl Solution {
139
+ pub fn find_closest (words : Vec <String >, word1 : String , word2 : String ) -> i32 {
140
+ let mut res = i32 :: MAX ;
141
+ let mut index1 = - 1 ;
142
+ let mut index2 = - 1 ;
143
+ for (i , word ) in words . iter (). enumerate () {
144
+ let i = i as i32 ;
145
+ if word . eq (& word1 ) {
146
+ index1 = i ;
147
+ } else if word . eq (& word2 ) {
148
+ index2 = i ;
149
+ }
150
+ if index1 != - 1 && index2 != - 1 {
151
+ res = res . min ((index1 - index2 ). abs ());
152
+ }
153
+ }
154
+ res
155
+ }
156
+ }
157
+ ```
158
+
135
159
### ** ...**
136
160
137
161
```
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn find_closest ( words : Vec < String > , word1 : String , word2 : String ) -> i32 {
3
+ let mut res = i32:: MAX ;
4
+ let mut index1 = -1 ;
5
+ let mut index2 = -1 ;
6
+ for ( i, word) in words. iter ( ) . enumerate ( ) {
7
+ let i = i as i32 ;
8
+ if word. eq ( & word1) {
9
+ index1 = i;
10
+ } else if word. eq ( & word2) {
11
+ index2 = i;
12
+ }
13
+ if index1 != -1 && index2 != -1 {
14
+ res = res. min ( ( index1 - index2) . abs ( ) ) ;
15
+ }
16
+ }
17
+ res
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments