File tree 3 files changed +61
-0
lines changed
solution/0000-0099/0035.Search Insert Position
3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -155,6 +155,28 @@ var searchInsert = function (nums, target) {
155
155
};
156
156
```
157
157
158
+ ### ** Rust**
159
+
160
+ ``` rust
161
+ use std :: cmp :: Ordering ;
162
+
163
+ impl Solution {
164
+ pub fn search_insert (nums : Vec <i32 >, target : i32 ) -> i32 {
165
+ let mut l = 0 ;
166
+ let mut r = nums . len ();
167
+ while l < r {
168
+ let mid = l + (r - l ) / 2 ;
169
+ match nums [mid ]. cmp (& target ) {
170
+ Ordering :: Less => l = mid + 1 ,
171
+ Ordering :: Greater => r = mid ,
172
+ Ordering :: Equal => return mid as i32 ,
173
+ }
174
+ }
175
+ l as i32
176
+ }
177
+ }
178
+ ```
179
+
158
180
### ** ...**
159
181
160
182
```
Original file line number Diff line number Diff line change @@ -131,6 +131,28 @@ var searchInsert = function (nums, target) {
131
131
};
132
132
```
133
133
134
+ ### ** Rust**
135
+
136
+ ``` rust
137
+ use std :: cmp :: Ordering ;
138
+
139
+ impl Solution {
140
+ pub fn search_insert (nums : Vec <i32 >, target : i32 ) -> i32 {
141
+ let mut l = 0 ;
142
+ let mut r = nums . len ();
143
+ while l < r {
144
+ let mid = l + (r - l ) / 2 ;
145
+ match nums [mid ]. cmp (& target ) {
146
+ Ordering :: Less => l = mid + 1 ,
147
+ Ordering :: Greater => r = mid ,
148
+ Ordering :: Equal => return mid as i32 ,
149
+ }
150
+ }
151
+ l as i32
152
+ }
153
+ }
154
+ ```
155
+
134
156
### ** ...**
135
157
136
158
```
Original file line number Diff line number Diff line change
1
+ use std:: cmp:: Ordering ;
2
+
3
+ impl Solution {
4
+ pub fn search_insert ( nums : Vec < i32 > , target : i32 ) -> i32 {
5
+ let mut l = 0 ;
6
+ let mut r = nums. len ( ) ;
7
+ while l < r {
8
+ let mid = l + ( r - l) / 2 ;
9
+ match nums[ mid] . cmp ( & target) {
10
+ Ordering :: Less => l = mid + 1 ,
11
+ Ordering :: Greater => r = mid,
12
+ Ordering :: Equal => return mid as i32 ,
13
+ }
14
+ }
15
+ l as i32
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments