mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Merge branch 'youngyangyang04:master' into remote
This commit is contained in:
@ -40,7 +40,7 @@
|
||||
本题首先要清楚两点:
|
||||
|
||||
* 只有一只股票!
|
||||
* 当前只有买股票或者买股票的操作
|
||||
* 当前只有买股票或者卖股票的操作
|
||||
|
||||
想获得利润至少要两天为一个交易单元。
|
||||
|
||||
|
@ -209,7 +209,50 @@ var findContentChildren = function(g, s) {
|
||||
|
||||
```
|
||||
|
||||
### TypeScript
|
||||
|
||||
```typescript
|
||||
// 大饼干尽量喂胃口大的
|
||||
function findContentChildren(g: number[], s: number[]): number {
|
||||
g.sort((a, b) => a - b);
|
||||
s.sort((a, b) => a - b);
|
||||
const childLength: number = g.length,
|
||||
cookieLength: number = s.length;
|
||||
let curChild: number = childLength - 1,
|
||||
curCookie: number = cookieLength - 1;
|
||||
let resCount: number = 0;
|
||||
while (curChild >= 0 && curCookie >= 0) {
|
||||
if (g[curChild] <= s[curCookie]) {
|
||||
curCookie--;
|
||||
resCount++;
|
||||
}
|
||||
curChild--;
|
||||
}
|
||||
return resCount;
|
||||
};
|
||||
```
|
||||
|
||||
```typescript
|
||||
// 小饼干先喂饱小胃口的
|
||||
function findContentChildren(g: number[], s: number[]): number {
|
||||
g.sort((a, b) => a - b);
|
||||
s.sort((a, b) => a - b);
|
||||
const childLength: number = g.length,
|
||||
cookieLength: number = s.length;
|
||||
let curChild: number = 0,
|
||||
curCookie: number = 0;
|
||||
while (curChild < childLength && curCookie < cookieLength) {
|
||||
if (g[curChild] <= s[curCookie]) {
|
||||
curChild++;
|
||||
}
|
||||
curCookie++;
|
||||
}
|
||||
return curChild;
|
||||
};
|
||||
```
|
||||
|
||||
### C
|
||||
|
||||
```c
|
||||
int cmp(int* a, int* b) {
|
||||
return *a - *b;
|
||||
|
Reference in New Issue
Block a user