Skip to content

Commit f59a988

Browse files
authored
Create 1700-number-of-students-unable-to-eat-lunch.js
1 parent 2cf8781 commit f59a988

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @param {number[]} students
3+
* @param {number[]} sandwiches
4+
* @return {number}
5+
*/
6+
const countStudents = function(students, sandwiches) {
7+
const n = students.length
8+
let res = n
9+
while(helper(students, sandwiches)) {
10+
const len = students.length
11+
for(let i = 0; i < len; i++) {
12+
if (students[0] === sandwiches[0]) {
13+
students.shift()
14+
sandwiches.shift()
15+
res--
16+
} else {
17+
const tmp = students[0]
18+
students.shift()
19+
students.push(tmp)
20+
}
21+
}
22+
}
23+
return res
24+
};
25+
26+
function helper(stu, san) {
27+
const n = stu.length
28+
let res = false
29+
for(let i = 0; i < n; i++) {
30+
if (stu[i] === san[0]) {
31+
return true
32+
}
33+
}
34+
return res
35+
}

0 commit comments

Comments
 (0)