All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0401_0500.s0455_assign_cookies.Solution Maven / Gradle / Ivy

There is a newer version: 1.24
Show newest version
package g0401_0500.s0455_assign_cookies;

// #Easy #Array #Sorting #Greedy #2022_07_18_Time_12_ms_(41.00%)_Space_52.6_MB_(78.45%)

import java.util.Arrays;

public class Solution {
    public int findContentChildren(int[] g, int[] s) {
        Arrays.sort(g);
        Arrays.sort(s);
        int result = 0;
        int i = 0;
        int j = 0;
        while (i < g.length && j < s.length) {
            if (s[j] >= g[i]) {
                result++;
                i++;
            }
            j++;
        }
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy