mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 07:35:35 +08:00
Update 0455.分发饼干.md
This commit is contained in:
@ -219,19 +219,17 @@ func findContentChildren(g []int, s []int) int {
|
|||||||
|
|
||||||
### Rust
|
### Rust
|
||||||
```rust
|
```rust
|
||||||
pub fn find_content_children(children: Vec<i32>, cookie: Vec<i32>) -> i32 {
|
pub fn find_content_children(mut children: Vec<i32>, mut cookie: Vec<i32>) -> i32 {
|
||||||
let mut children = children;
|
|
||||||
let mut cookies = cookie;
|
|
||||||
children.sort();
|
children.sort();
|
||||||
cookies.sort();
|
cookies.sort();
|
||||||
|
|
||||||
let (mut child, mut cookie) = (0usize, 0usize);
|
let (mut child, mut cookie) = (0, 0);
|
||||||
while child < children.len() && cookie < cookies.len() {
|
while child < children.len() && cookie < cookies.len() {
|
||||||
// 优先选择最小饼干喂饱孩子
|
// 优先选择最小饼干喂饱孩子
|
||||||
if children[child] <= cookies[cookie] {
|
if children[child] <= cookies[cookie] {
|
||||||
child += 1;
|
child += 1;
|
||||||
}
|
}
|
||||||
cookie += 1
|
cookie += 1;
|
||||||
}
|
}
|
||||||
child as i32
|
child as i32
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user