File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -73,9 +73,9 @@ public:
73
73
}
74
74
};
75
75
```
76
- * 时间复杂度:O(nlogn)
77
- * 空间复杂度:O(1)
78
76
77
+ - 时间复杂度:O(nlogn)
78
+ - 空间复杂度:O(1)
79
79
80
80
从代码中可以看出我用了一个 index 来控制饼干数组的遍历,遍历饼干并没有再起一个 for 循环,而是采用自减的方式,这也是常用的技巧。
81
81
@@ -119,9 +119,9 @@ public:
119
119
}
120
120
};
121
121
```
122
- * 时间复杂度:O(nlogn)
123
- * 空间复杂度:O(1)
124
122
123
+ - 时间复杂度:O(nlogn)
124
+ - 空间复杂度:O(1)
125
125
126
126
细心的录友可以发现,这种写法,两个循环的顺序改变了,先遍历的饼干,在遍历的胃口,这是因为遍历顺序变了,我们是从小到大遍历。
127
127
@@ -177,7 +177,9 @@ class Solution {
177
177
```
178
178
179
179
### Python
180
+
180
181
贪心 大饼干优先
182
+
181
183
``` python
182
184
class Solution :
183
185
def findContentChildren (self , g , s ):
@@ -192,7 +194,9 @@ class Solution:
192
194
return result
193
195
194
196
```
197
+
195
198
贪心 小饼干优先
199
+
196
200
``` python
197
201
class Solution :
198
202
def findContentChildren (self , g , s ):
@@ -229,7 +233,7 @@ func findContentChildren(g []int, s []int) int {
229
233
### Rust
230
234
231
235
``` rust
232
- pub fn find_content_children (mut children : Vec <i32 >, mut cookie : Vec <i32 >) -> i32 {
236
+ pub fn find_content_children (mut children : Vec <i32 >, mut cookies : Vec <i32 >) -> i32 {
233
237
children . sort ();
234
238
cookies . sort ();
235
239
@@ -378,7 +382,9 @@ object Solution {
378
382
}
379
383
}
380
384
```
385
+
381
386
### C#
387
+
382
388
``` csharp
383
389
public class Solution
384
390
{
You can’t perform that action at this time.
0 commit comments