
g0401_0500.s0455_assign_cookies.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java17 Show documentation
Show all versions of leetcode-in-java17 Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
package g0401_0500.s0455_assign_cookies;
// #Easy #Array #Sorting #Greedy #2022_03_18_Time_11_ms_(42.95%)_Space_54.7_MB_(6.90%)
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 - 2025 Weber Informatics LLC | Privacy Policy