File tree 2 files changed +30
-0
lines changed
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ package easy ;
2
+
3
+ import java .util .Arrays ;
4
+
5
+ public class AssignCookies {
6
+
7
+ public int findContentChildren (int [] g , int [] s ) {
8
+ Arrays .sort (g );
9
+ Arrays .sort (s );
10
+
11
+ int result = 0 ;
12
+ for (int i = 0 , j = 0 ; i < g .length && j < s .length ;){
13
+ if (s [j ] >= g [i ]) {
14
+ result ++;
15
+ i ++;
16
+ }
17
+ j ++;
18
+ }
19
+ return result ;
20
+ }
21
+
22
+ public static void main (String ...args ){
23
+ AssignCookies test = new AssignCookies ();
24
+ int [] g = new int []{1 ,2 ,3 };
25
+ int [] s = new int []{1 ,1 };
26
+ System .out .println (test .findContentChildren (g , s ));
27
+ }
28
+
29
+ }
Original file line number Diff line number Diff line change 1
1
# fishercoderLeetcode
2
2
| # | Title | Solutions | Time | Space | Difficulty | Tag | Notes
3
3
|-----|----------------|---------------|---------------|---------------|-------------|--------------|-----
4
+ | 455| [ Assign Cookies] ( https://leetcode.com/problems/assign-cookies/ ) | [ Solution] ( ../../blob/master/EASY/src/easy/AssignCookies.java ) | O(n)| O(1) | Easy|
4
5
| 453| [ Minimum Moves to Equal Array Elements] ( https://leetcode.com/problems/minimum-moves-to-equal-array-elements/ ) | [ Solution] ( ../../blob/master/EASY/src/easy/MinimumMovestoEqualArrayElements.java ) | O(n)| O(1) | Easy|
5
6
|447|[ Number of Boomerangs] ( https://leetcode.com/problems/number-of-boomerangs/ ) |[ Solution] ( ../../blob/master/EASY/src/easy/NumberofBoomerangs.java ) | O(n^2)|O(n) | Easy| HashMap
6
7
| 441| [ Arranging Coins] ( https://leetcode.com/problems/arrange-coins/ ) | [ Solution] ( ../../blob/master/EASY/src/easy/ArrangingCoins.java ) | O(n)| O(1) | Easy|
You can’t perform that action at this time.
0 commit comments