Skip to content

Commit 5b5d079

Browse files
solves assign cookies
1 parent 3785d82 commit 5b5d079

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
| 447 | [Number of Boomerangs](https://leetcode.com/problems/number-of-boomerangs) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NumberOfBoomerangs.java) |
120120
| 448 | [Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FindAllNumbersDisappearedInAnArray.java) |
121121
| 453 | [Minimum Moves to Equal Array Elements](https://leetcode.com/problems/minimum-moves-to-equal-array-elements) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MinimumMovesToEqualArrayElements.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/minimum_moves_to_equal_array_element.py) |
122-
| 455 | [Assign Cookies](https://leetcode.com/problems/assign-cookies) | Easy | |
122+
| 455 | [Assign Cookies](https://leetcode.com/problems/assign-cookies) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/AssignCookies.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/assign_cookies.py)|
123123
| 459 | [Repeated Substring Pattern](https://leetcode.com/problems/repeated-substring-pattern) | Easy | |
124124
| 461 | [Hamming Distance](https://leetcode.com/problems/hamming-distance) | Easy | |
125125
| 463 | [Island Perimeter](https://leetcode.com/problems/island-perimeter) | Easy | |

Diff for: python/assign_cookies.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def findContentChildren(self, g: List[int], s: List[int]) -> int:
6+
s.sort()
7+
g.sort()
8+
i = 0
9+
contendedChildren = 0
10+
for j in range(len(s)):
11+
if i < len(g) and s[j] >= g[i]:
12+
contendedChildren += 1
13+
i += 1
14+
return contendedChildren

Diff for: src/AssignCookies.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Problem Number: 455
2+
// https://leetcode.com/problems/assign-cookies/
3+
4+
import java.util.Arrays;
5+
6+
public class AssignCookies {
7+
public int findContentChildren(int[] g, int[] s) {
8+
Arrays.sort(g);
9+
Arrays.sort(s);
10+
int contendedChildren = 0;
11+
for (int i= 0, j = 0 ; i < g.length && j < s.length ; j++) {
12+
if (s[j] >= g[i]) {
13+
contendedChildren++;
14+
i++;
15+
}
16+
}
17+
return contendedChildren;
18+
}
19+
}

0 commit comments

Comments
 (0)