Merge pull request #1927 from fwqaaq/patch-7

Update 0455.分发饼干.md 优化 rust 写法
This commit is contained in:
程序员Carl
2023-03-09 09:57:56 +08:00
committed by GitHub

View File

@ -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
}