mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
添加 0455.分发饼干.md Scala版本
This commit is contained in:
@ -296,5 +296,26 @@ int findContentChildren(int* g, int gSize, int* s, int sSize){
|
||||
}
|
||||
```
|
||||
|
||||
### Scala
|
||||
|
||||
```scala
|
||||
object Solution {
|
||||
def findContentChildren(g: Array[Int], s: Array[Int]): Int = {
|
||||
var result = 0
|
||||
var children = g.sorted
|
||||
var cookie = s.sorted
|
||||
// 遍历饼干
|
||||
var j = 0
|
||||
for (i <- cookie.indices) {
|
||||
if (j < children.size && cookie(i) >= children(j)) {
|
||||
j += 1
|
||||
result += 1
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
-----------------------
|
||||
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
||||
|
Reference in New Issue
Block a user