leetcode 455. Assign Cookies

    xiaoxiao2025-01-08  13

    贪心算法

    public static int findContentChildren(int[] g, int[] s) { //默认排序从小到大 Arrays.sort(g); System.out.println(Arrays.toString(g)); Arrays.sort(s); System.out.println(Arrays.toString(s)); int res=0; int i=0; int j=0; while(i<g.length && j<s.length){ if(g[i]<=s[j]){ i++; j++; res++; }else{ j++; } } return res; }

     

    最新回复(0)