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