mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
update 455.分发饼干; 代码报错
This commit is contained in:
@ -73,9 +73,9 @@ public:
|
||||
}
|
||||
};
|
||||
```
|
||||
* 时间复杂度:O(nlogn)
|
||||
* 空间复杂度:O(1)
|
||||
|
||||
- 时间复杂度:O(nlogn)
|
||||
- 空间复杂度:O(1)
|
||||
|
||||
从代码中可以看出我用了一个 index 来控制饼干数组的遍历,遍历饼干并没有再起一个 for 循环,而是采用自减的方式,这也是常用的技巧。
|
||||
|
||||
@ -119,9 +119,9 @@ public:
|
||||
}
|
||||
};
|
||||
```
|
||||
* 时间复杂度:O(nlogn)
|
||||
* 空间复杂度:O(1)
|
||||
|
||||
- 时间复杂度:O(nlogn)
|
||||
- 空间复杂度:O(1)
|
||||
|
||||
细心的录友可以发现,这种写法,两个循环的顺序改变了,先遍历的饼干,在遍历的胃口,这是因为遍历顺序变了,我们是从小到大遍历。
|
||||
|
||||
@ -177,9 +177,7 @@ class Solution {
|
||||
```
|
||||
|
||||
### Python
|
||||
|
||||
贪心 大饼干优先
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def findContentChildren(self, g, s):
|
||||
@ -194,9 +192,7 @@ class Solution:
|
||||
return result
|
||||
|
||||
```
|
||||
|
||||
贪心 小饼干优先
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def findContentChildren(self, g, s):
|
||||
@ -382,9 +378,7 @@ object Solution {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### C#
|
||||
|
||||
```csharp
|
||||
public class Solution
|
||||
{
|
||||
|
Reference in New Issue
Block a user