File tree Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ impl Solution {
70
70
std强大的标准库 Vec上retain方法
71
71
72
72
``` rust
73
-
73
+ # struct Solution {}
74
74
impl Solution {
75
75
pub fn remove_element (nums : & mut Vec <i32 >, val : i32 ) -> i32 {
76
76
nums . retain (| & x | x != val );
@@ -83,6 +83,7 @@ impl Solution {
83
83
slow指针用来存储需要留下元素应该存放的地址,fast指针是当前处理的元素
84
84
85
85
``` rust
86
+ # struct Solution {}
86
87
impl Solution {
87
88
pub fn remove_element (nums : & mut Vec <i32 >, val : i32 ) -> i32 {
88
89
let mut slow : usize = 0usize ; // the result elem
Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ impl Solution {
91
91
- ` Ordering::Less => { right = mid } ` 要注意“右开” 又写错了
92
92
93
93
``` rust
94
-
94
+ # struct Solution {}
95
95
use std :: cmp :: Ordering ;
96
96
97
97
impl Solution {
@@ -117,6 +117,7 @@ impl Solution {
117
117
使用rust std
118
118
119
119
``` rust
120
+ # struct Solution {}
120
121
impl Solution {
121
122
pub fn search (nums : Vec <i32 >, target : i32 ) -> i32 {
122
123
match nums . binary_search (& target ) {
@@ -126,6 +127,9 @@ impl Solution {
126
127
}
127
128
}
128
129
130
+
131
+ ```rust
132
+ # struct Solution {}
129
133
impl Solution {
130
134
pub fn search (nums : Vec <i32 >, target : i32 ) -> i32 {
131
135
let idx : usize = nums . partition_point (| & x | x < target );
You can’t perform that action at this time.
0 commit comments