File tree 2 files changed +46
-0
lines changed
solution/2500-2599/2515.Shortest Distance to Target String in a Circular Array
2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -198,6 +198,29 @@ impl Solution {
198
198
}
199
199
```
200
200
201
+ ``` rust
202
+ use std :: cmp :: min;
203
+
204
+ impl Solution {
205
+ pub fn closet_target (words : Vec <String >, target : String , start_index : i32 ) -> i32 {
206
+ let mut ans = words . len ();
207
+
208
+ for (i , w ) in words . iter (). enumerate () {
209
+ if * w == target {
210
+ let t = (i as i32 - start_index ). abs ();
211
+ ans = min (ans , min (t as usize , words . len () - t as usize ));
212
+ }
213
+ }
214
+
215
+ if ans == words . len () {
216
+ return - 1 ;
217
+ }
218
+
219
+ ans as i32
220
+ }
221
+ }
222
+ ```
223
+
201
224
### ** C**
202
225
203
226
``` c
Original file line number Diff line number Diff line change @@ -185,6 +185,29 @@ impl Solution {
185
185
}
186
186
```
187
187
188
+ ``` rust
189
+ use std :: cmp :: min;
190
+
191
+ impl Solution {
192
+ pub fn closet_target (words : Vec <String >, target : String , start_index : i32 ) -> i32 {
193
+ let mut ans = words . len ();
194
+
195
+ for (i , w ) in words . iter (). enumerate () {
196
+ if * w == target {
197
+ let t = (i as i32 - start_index ). abs ();
198
+ ans = min (ans , min (t as usize , words . len () - t as usize ));
199
+ }
200
+ }
201
+
202
+ if ans == words . len () {
203
+ return - 1 ;
204
+ }
205
+
206
+ ans as i32
207
+ }
208
+ }
209
+ ```
210
+
188
211
### ** C**
189
212
190
213
``` c
You can’t perform that action at this time.
0 commit comments