Skip to content

Commit a07b44a

Browse files
committed
feat: add rust solution to lcof problem: No.11
剑指 Offer 11. 旋转数组的最小数字
1 parent 5475ccd commit a07b44a

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lcof/面试题11. 旋转数组的最小数字/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,26 @@ public:
125125
};
126126
```
127127
128+
### **Rust**
129+
130+
```rust
131+
impl Solution {
132+
pub fn min_array(numbers: Vec<i32>) -> i32 {
133+
let mut l = 0;
134+
let mut r = numbers.len() - 1;
135+
while l < r {
136+
let mid = l + r >> 1;
137+
match numbers[mid].cmp(&numbers[r]) {
138+
std::cmp::Ordering::Less => r = mid,
139+
std::cmp::Ordering::Equal => r -= 1,
140+
std::cmp::Ordering::Greater => l = mid + 1,
141+
}
142+
}
143+
numbers[l]
144+
}
145+
}
146+
```
147+
128148
### **...**
129149

130150
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
impl Solution {
2+
pub fn min_array(numbers: Vec<i32>) -> i32 {
3+
let mut l = 0;
4+
let mut r = numbers.len() - 1;
5+
while l < r {
6+
let mid = l + r >> 1;
7+
match numbers[mid].cmp(&numbers[r]) {
8+
std::cmp::Ordering::Less => r = mid,
9+
std::cmp::Ordering::Equal => r -= 1,
10+
std::cmp::Ordering::Greater => l = mid + 1,
11+
}
12+
}
13+
numbers[l]
14+
}
15+
}

0 commit comments

Comments
 (0)