Skip to content

Commit b2afdff

Browse files
committed
feat: add solutions to lc problem: No.1700
No.1700.Number of Students Unable to Eat Lunch
1 parent 88aece0 commit b2afdff

File tree

5 files changed

+159
-0
lines changed

5 files changed

+159
-0
lines changed

solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,64 @@ func countStudents(students []int, sandwiches []int) int {
143143
}
144144
```
145145

146+
### **C**
147+
148+
```c
149+
int countStudents(int *students, int studentsSize, int *sandwiches, int sandwichesSize) {
150+
int count[2] = {0};
151+
for (int i = 0; i < studentsSize; i++) {
152+
count[students[i]]++;
153+
}
154+
for (int i = 0; i < sandwichesSize; i++) {
155+
int j = sandwiches[i];
156+
if (count[j] == 0) {
157+
return count[j ^ 1];
158+
}
159+
count[j]--;
160+
}
161+
return 0;
162+
}
163+
```
164+
165+
### **TypeScript**
166+
167+
```ts
168+
function countStudents(students: number[], sandwiches: number[]): number {
169+
const count = [0, 0];
170+
for (const v of students) {
171+
count[v]++;
172+
}
173+
for (const v of sandwiches) {
174+
if (count[v] === 0) {
175+
return count[v ^ 1];
176+
}
177+
count[v]--;
178+
}
179+
return 0;
180+
}
181+
```
182+
183+
### **Rust**
184+
185+
```rust
186+
impl Solution {
187+
pub fn count_students(students: Vec<i32>, sandwiches: Vec<i32>) -> i32 {
188+
let mut count = [0, 0];
189+
for &v in students.iter() {
190+
count[v as usize] += 1;
191+
}
192+
for &v in sandwiches.iter() {
193+
let v = v as usize;
194+
if count[v as usize] == 0 {
195+
return count[v ^ 1];
196+
}
197+
count[v] -= 1;
198+
}
199+
0
200+
}
201+
}
202+
```
203+
146204
### **...**
147205

148206
```

solution/1700-1799/1700.Number of Students Unable to Eat Lunch/README_EN.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,64 @@ func countStudents(students []int, sandwiches []int) int {
126126
}
127127
```
128128

129+
### **C**
130+
131+
```c
132+
int countStudents(int *students, int studentsSize, int *sandwiches, int sandwichesSize) {
133+
int count[2] = {0};
134+
for (int i = 0; i < studentsSize; i++) {
135+
count[students[i]]++;
136+
}
137+
for (int i = 0; i < sandwichesSize; i++) {
138+
int j = sandwiches[i];
139+
if (count[j] == 0) {
140+
return count[j ^ 1];
141+
}
142+
count[j]--;
143+
}
144+
return 0;
145+
}
146+
```
147+
148+
### **TypeScript**
149+
150+
```ts
151+
function countStudents(students: number[], sandwiches: number[]): number {
152+
const count = [0, 0];
153+
for (const v of students) {
154+
count[v]++;
155+
}
156+
for (const v of sandwiches) {
157+
if (count[v] === 0) {
158+
return count[v ^ 1];
159+
}
160+
count[v]--;
161+
}
162+
return 0;
163+
}
164+
```
165+
166+
### **Rust**
167+
168+
```rust
169+
impl Solution {
170+
pub fn count_students(students: Vec<i32>, sandwiches: Vec<i32>) -> i32 {
171+
let mut count = [0, 0];
172+
for &v in students.iter() {
173+
count[v as usize] += 1;
174+
}
175+
for &v in sandwiches.iter() {
176+
let v = v as usize;
177+
if count[v as usize] == 0 {
178+
return count[v ^ 1];
179+
}
180+
count[v] -= 1;
181+
}
182+
0
183+
}
184+
}
185+
```
186+
129187
### **...**
130188

131189
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
int countStudents(int *students, int studentsSize, int *sandwiches, int sandwichesSize) {
2+
int count[2] = {0};
3+
for (int i = 0; i < studentsSize; i++) {
4+
count[students[i]]++;
5+
}
6+
for (int i = 0; i < sandwichesSize; i++) {
7+
int j = sandwiches[i];
8+
if (count[j] == 0) {
9+
return count[j ^ 1];
10+
}
11+
count[j]--;
12+
}
13+
return 0;
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
impl Solution {
2+
pub fn count_students(students: Vec<i32>, sandwiches: Vec<i32>) -> i32 {
3+
let mut count = [0, 0];
4+
for &v in students.iter() {
5+
count[v as usize] += 1;
6+
}
7+
for &v in sandwiches.iter() {
8+
let v = v as usize;
9+
if count[v as usize] == 0 {
10+
return count[v ^ 1];
11+
}
12+
count[v] -= 1;
13+
}
14+
0
15+
}
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function countStudents(students: number[], sandwiches: number[]): number {
2+
const count = [0, 0];
3+
for (const v of students) {
4+
count[v]++;
5+
}
6+
for (const v of sandwiches) {
7+
if (count[v] === 0) {
8+
return count[v ^ 1];
9+
}
10+
count[v]--;
11+
}
12+
return 0;
13+
}

0 commit comments

Comments
 (0)