zoukankan      html  css  js  c++  java
  • assign-cookies

    https://leetcode.com/problems/assign-cookies/

    用贪心算法即可。

    package com.company;
    
    
    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.Map;
    
    class Solution {
        public int findContentChildren(int[] g, int[] s) {
            Arrays.sort(g);
            Arrays.sort(s);
            int i=0, j=0;
            for (; i<g.length; i++) {
                while (j < s.length && g[i] > s[j]) {
                    j++;
                }
                if (j == s.length) {
                    break;
                }
                j++;
            }
            return i;
        }
    }
    
    public class Main {
    
        public static void main(String[] args) throws InterruptedException {
    
            System.out.println("Hello!");
            Solution solution = new Solution();
    
            // Your Codec object will be instantiated and called as such:
            int[] g = {1, 2, 3};
            int[] s = {3};
            int ret = solution.findContentChildren(g, s);
            System.out.printf("ret:%d
    ", ret);
    
            System.out.println();
    
        }
    
    }
  • 相关阅读:
    this指向
    作用域链
    入门
    一、servlet之初见
    jdbc之mysql
    第六章、树和二叉树
    第七章、暴力求解法
    机试
    第十三章、字符串
    栈和队列
  • 原文地址:https://www.cnblogs.com/charlesblc/p/6075049.html
Copyright © 2011-2022 走看看