算法 贪心核心思想 挺经典的贪心法吧,小孩子只能吃一块饼干注意一下就行了。 PS:我还重写了一下排序算法代码 class Solution { public static void swap(int[] a, int i, int j){ int temp; temp = a[i]; a[i] = a[j]; a[j] = temp; } public static int[] selectionSort(int[] result){ int temp; for(int i = 0;i <result.length;i++){ int min = i; for (int j = i;j < result.length;j++){ if(result[j] < result[min]){ min = j; } } swap(result,i,min); } return result; } public int findContentChildren(int[] g, int[] s) { selectionSort(g); selectionSort(s); int count = 0,j = 0; for(int i = 0;i < s.length;++i){ if(s[i] >= g[j]){ count++; j++; } if(j == g.length) return count; } return count; } }