From f9079ddc18206cd8a16eeb8085808b65ecab6d6e Mon Sep 17 00:00:00 2001 From: Steve2020 <841532108@qq.com> Date: Tue, 5 Apr 2022 10:56:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=880455.=E5=88=86?= =?UTF-8?q?=E5=8F=91=E9=A5=BC=E5=B9=B2.md=EF=BC=89=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0typescript=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0455.分发饼干.md | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/problems/0455.分发饼干.md b/problems/0455.分发饼干.md index 210b492d..f012df68 100644 --- a/problems/0455.分发饼干.md +++ b/problems/0455.分发饼干.md @@ -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; From c4992be374628782d18ffa8648fa1443825bc947 Mon Sep 17 00:00:00 2001 From: Lafish <34953046+LeUKi@users.noreply.github.com> Date: Wed, 6 Apr 2022 08:52:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B00122.=E4=B9=B0=E5=8D=96?= =?UTF-8?q?=E8=82=A1=E7=A5=A8=E7=9A=84=E6=9C=80=E4=BD=B3=E6=97=B6=E6=9C=BA?= =?UTF-8?q?II=EF=BC=9A=E9=94=99=E5=AD=97=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0122.买卖股票的最佳时机II.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/0122.买卖股票的最佳时机II.md b/problems/0122.买卖股票的最佳时机II.md index 83b852c6..b31cbae3 100644 --- a/problems/0122.买卖股票的最佳时机II.md +++ b/problems/0122.买卖股票的最佳时机II.md @@ -40,7 +40,7 @@ 本题首先要清楚两点: * 只有一只股票! -* 当前只有买股票或者买股票的操作 +* 当前只有买股票或者卖股票的操作 想获得利润至少要两天为一个交易单元。