Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ainevsia committed Oct 1, 2024
1 parent 4dcb6d7 commit 4140dd8
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion notes/src/day2/lc209.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,21 @@ impl Solution {
}
}

```
```

在闭包中使用pattern matching来去除变量前边的引用的时候,有时候不要去除多了

```js
pub fn min_sub_array_len(nums: Vec<i32>) {
nums.iter().scan(1i32, |&mut st, &x| {
st += x;
Some(st)
});
}

```

类似这个时候,st绑定到的就永远都是输入的那个1 到闭包函数内了,起不到修改闭包外的1的效果。

所以这个引用就不要自动匹配掉了,就手动解引用吧

0 comments on commit 4140dd8

Please sign in to comment.