File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff 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
214257int cmp (int* a, int* b) {
215258 return * a - * b;
You can’t perform that action at this time.
0 commit comments