算法: Assign cookies

Assign Cookies

class Solution {
    func findContentChildren(_ g: [Int], _ s: [Int]) -> Int {
        var gg = g.sorted()
        var ss = s.sorted()
        var ans = 0
        var j = 0
        for ele in gg {
            while (j < ss.count && ss[j] < ele) {
                j += 1
            }
            if j < ss.count {
                ans += 1
                j = j + 1
            }
        }
        return ans
    }
}
    原文作者:TimberTang
    原文地址: https://www.jianshu.com/p/2a4c47ea94fe
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞