Skip to content

Commit 4140dd8

Browse files
committed
1
1 parent 4dcb6d7 commit 4140dd8

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

notes/src/day2/lc209.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,21 @@ impl Solution {
8383
}
8484
}
8585

86-
```
86+
```
87+
88+
在闭包中使用pattern matching来去除变量前边的引用的时候,有时候不要去除多了
89+
90+
```js
91+
pub fn min_sub_array_len(nums: Vec<i32>) {
92+
nums.iter().scan(1i32, |&mut st, &x| {
93+
st += x;
94+
Some(st)
95+
});
96+
}
97+
98+
```
99+
100+
类似这个时候,st绑定到的就永远都是输入的那个1 到闭包函数内了,起不到修改闭包外的1的效果。
101+
102+
所以这个引用就不要自动匹配掉了,就手动解引用吧
103+

0 commit comments

Comments
 (0)