-
星空
class Solution(object): def findContentChildren(self, g, s): """ :type g: List[int] :type s: List[int] :rtype: int """ cnt = 0 i, j = len(g) - 1, len(s) - 1 g, s = sorted(g), sorted(s) while min(i, j) >= 0: if g[i] <= s[j]: cnt += 1 j -= 1 i -= 1 return cnt
-
星空
class Solution { public int findContentChildren(int[] g, int[] s) { Arrays.sort(g); Arrays.sort(s); int i = 0; for(int j=0;i<g.length && j<s.length;j++) { if(g[i]<=s[j]) i++; } return i; } }
-
星空
public class Solution { public int findContentChildren(int[] g, int[] s) { Arrays.sort(g); Arrays.sort(s); int pointG = 0; int pointS = 0; while (pointG<g.length && pointS<s.length) { if (g[pointG]<=s[pointS]) { pointG++; pointS++; } else { pointS++; } } return pointG; } }
-