Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cfc07d0

Browse files
Merge branch 'youngyangyang04:master' into remote
2 parents 84750ac + a265932 commit cfc07d0

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

‎problems/0122.买卖股票的最佳时机II.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
本题首先要清楚两点:
4141

4242
* 只有一只股票!
43-
* 当前只有买股票或者买股票的操作
43+
* 当前只有买股票或者卖股票的操作
4444

4545
想获得利润至少要两天为一个交易单元。
4646

‎problems/0455.分发饼干.md‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,50 @@ var findContentChildren = function(g, s) {
209209

210210
```
211211

212+
### TypeScript
213+
214+
```typescript
215+
// 大饼干尽量喂胃口大的
216+
function findContentChildren(g: number[], s: number[]): number {
217+
g.sort((a, b) => a - b);
218+
s.sort((a, b) => a - b);
219+
const childLength: number = g.length,
220+
cookieLength: number = s.length;
221+
let curChild: number = childLength - 1,
222+
curCookie: number = cookieLength - 1;
223+
let resCount: number = 0;
224+
while (curChild >= 0 && curCookie >= 0) {
225+
if (g[curChild] <= s[curCookie]) {
226+
curCookie--;
227+
resCount++;
228+
}
229+
curChild--;
230+
}
231+
return resCount;
232+
};
233+
```
234+
235+
```typescript
236+
// 小饼干先喂饱小胃口的
237+
function findContentChildren(g: number[], s: number[]): number {
238+
g.sort((a, b) => a - b);
239+
s.sort((a, b) => a - b);
240+
const childLength: number = g.length,
241+
cookieLength: number = s.length;
242+
let curChild: number = 0,
243+
curCookie: number = 0;
244+
while (curChild < childLength && curCookie < cookieLength) {
245+
if (g[curChild] <= s[curCookie]) {
246+
curChild++;
247+
}
248+
curCookie++;
249+
}
250+
return curChild;
251+
};
252+
```
253+
212254
### C
255+
213256
```c
214257
int cmp(int* a, int* b) {
215258
return *a - *b;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /