Skip to content

Commit 59d0222

Browse files
add 1700
1 parent a3d9269 commit 59d0222

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1700|[Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1700.java) ||Easy|Array|
1112
|1694|[Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1694.java) ||Easy|String|
1213
|1690|[Stone Game VII](https://leetcode.com/problems/stone-game-vii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1690.java) ||Medium|DP|
1314
|1688|[Count of Matches in Tournament](https://leetcode.com/problems/count-of-matches-in-tournament/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1688.java) ||Easy|Backtracking|
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.LinkedList;
4+
import java.util.Queue;
5+
6+
public class _1700 {
7+
public static class Solution1 {
8+
public int countStudents(int[] students, int[] sandwiches) {
9+
Queue<Integer> studentsQueue = new LinkedList<>();
10+
Queue<Integer> sandwichesQueue = new LinkedList<>();
11+
for (int i = 0; i < sandwiches.length; i++) {
12+
studentsQueue.add(students[i]);
13+
sandwichesQueue.add(sandwiches[i]);
14+
}
15+
do {
16+
if (!studentsQueue.isEmpty()) {
17+
if (studentsQueue.peek() == sandwichesQueue.peek()) {
18+
studentsQueue.poll();
19+
sandwichesQueue.poll();
20+
} else {
21+
if (!studentsQueue.contains(sandwichesQueue.peek())) {
22+
break;
23+
}
24+
studentsQueue.add(studentsQueue.poll());
25+
}
26+
}
27+
} while (!studentsQueue.isEmpty());
28+
return studentsQueue.size();
29+
}
30+
}
31+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1700;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1700Test {
10+
private static _1700.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1700.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(0, solution1.countStudents(new int[]{1, 1, 0, 0}, new int[]{0, 1, 0, 1}));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(3, solution1.countStudents(new int[]{1, 1, 1, 0, 0, 1}, new int[]{1, 0, 0, 0, 1, 1}));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)