Skip to content

Files

Latest commit

 

History

History
23 lines (21 loc) · 471 Bytes

455.assign-cookies.md

File metadata and controls

23 lines (21 loc) · 471 Bytes

Greedy

fun findContentChildren(g: IntArray, s: IntArray): Int {
    g.sort()
    s.sort()

    var gIndex = 0
    var sIndex = 0
    var count = 0
    while (gIndex < g.size && sIndex < s.size) {
        if (g[gIndex] <= s[sIndex]) {
            gIndex++
            sIndex++
            count++
        } else {
            sIndex++
        }
    }
    return count
}