题目链接

题目描述

image.png

思路

ps:官方的没看懂思路,这个可以 https://leetcode-cn.com/problems/assign-cookies/solution/dai-ma-sui-xiang-lu-dai-ni-xue-tou-tan-x-6jsc/

  1. public int findContentChildren(int[] g, int[] s) {
  2. Arrays.sort(g);
  3. Arrays.sort(s);
  4. int numOfChildren = g.length;
  5. int numOfCookies = s.length;
  6. int count = 0;
  7. for (int i = 0, j = 0; i < numOfChildren && j < numOfCookies; i++, j++) {
  8. while (j < numOfCookies && g[i] > s[j]) {
  9. j++;
  10. }
  11. if (j < numOfCookies) {
  12. count++;
  13. }
  14. }
  15. return count;
  16. }