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 18f29ef

Browse files
committed
添加 0455.分发饼干.md Scala版本
1 parent af239ce commit 18f29ef

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎problems/0455.分发饼干.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,5 +296,26 @@ int findContentChildren(int* g, int gSize, int* s, int sSize){
296296
}
297297
```
298298
299+
### Scala
300+
301+
```scala
302+
object Solution {
303+
def findContentChildren(g: Array[Int], s: Array[Int]): Int = {
304+
var result = 0
305+
var children = g.sorted
306+
var cookie = s.sorted
307+
// 遍历饼干
308+
var j = 0
309+
for (i <- cookie.indices) {
310+
if (j < children.size && cookie(i) >= children(j)) {
311+
j += 1
312+
result += 1
313+
}
314+
}
315+
result
316+
}
317+
}
318+
```
319+
299320
-----------------------
300321
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

0 commit comments

Comments
(0)

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