Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit59d0222

Browse files
add 1700
1 parenta3d9269 commit59d0222

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+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.LinkedList;
4+
importjava.util.Queue;
5+
6+
publicclass_1700 {
7+
publicstaticclassSolution1 {
8+
publicintcountStudents(int[]students,int[]sandwiches) {
9+
Queue<Integer>studentsQueue =newLinkedList<>();
10+
Queue<Integer>sandwichesQueue =newLinkedList<>();
11+
for (inti =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+
returnstudentsQueue.size();
29+
}
30+
}
31+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1700;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1700Test {
10+
privatestatic_1700.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1700.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(0,solution1.countStudents(newint[]{1,1,0,0},newint[]{0,1,0,1}));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals(3,solution1.countStudents(newint[]{1,1,1,0,0,1},newint[]{1,0,0,0,1,1}));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp