定义长度为 的序列 表示队列中第 名学生的偏好,序列 表示栈顶至栈底的三明治类型( 为栈顶)。初始时,队列与栈均包含 名学生与 个三明治。每步操作如下: 若 ,则该学生取走该三明治并移出队列,三明治出栈; 否则,将队首学生移至队尾; 重复上述操作直至所有剩余学生均不满足栈顶三明治偏好。 你需要补全一个函数求无法拿到三明治的学生人数,接受的参数为: 整数序列 ,长度为 ; 整数序列 ,长度为 。 函数的返回值为一个正整数,表示无法拿到三明治的学生人数。
示例1
输入
[1,1,0,1],[1,0,0,1]
输出
2
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param students int整型一维数组 * @param sandwiches int整型一维数组 * @return int整型 */ public int countStudents (int[] students, int[] sandwiches) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param students int整型vector * @param sandwiches int整型vector * @return int整型 */ int countStudents(vector
& students, vector
& sandwiches) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param students int整型一维数组 # @param sandwiches int整型一维数组 # @return int整型 # class Solution: def countStudents(self , students , sandwiches ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param students int整型一维数组 * @param sandwiches int整型一维数组 * @return int整型 */ public int countStudents (List
students, List
sandwiches) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param students int整型一维数组 * @param sandwiches int整型一维数组 * @return int整型 */ function countStudents( students , sandwiches ) { // write code here } module.exports = { countStudents : countStudents };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param students int整型一维数组 # @param sandwiches int整型一维数组 # @return int整型 # class Solution: def countStudents(self , students: List[int], sandwiches: List[int]) -> int: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param students int整型一维数组 * @param sandwiches int整型一维数组 * @return int整型 */ func countStudents( students []int , sandwiches []int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param students int整型一维数组 * @param studentsLen int students数组长度 * @param sandwiches int整型一维数组 * @param sandwichesLen int sandwiches数组长度 * @return int整型 */ int countStudents(int* students, int studentsLen, int* sandwiches, int sandwichesLen ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param students int整型一维数组 # @param sandwiches int整型一维数组 # @return int整型 # class Solution def countStudents(students, sandwiches) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param students int整型一维数组 * @param sandwiches int整型一维数组 * @return int整型 */ def countStudents(students: Array[Int],sandwiches: Array[Int]): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param students int整型一维数组 * @param sandwiches int整型一维数组 * @return int整型 */ fun countStudents(students: IntArray,sandwiches: IntArray): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param students int整型一维数组 * @param sandwiches int整型一维数组 * @return int整型 */ public int countStudents (int[] students, int[] sandwiches) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param students int整型一维数组 * @param sandwiches int整型一维数组 * @return int整型 */ export function countStudents(students: number[], sandwiches: number[]): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param students int整型一维数组 * @param sandwiches int整型一维数组 * @return int整型 */ func countStudents ( _ students: [Int], _ sandwiches: [Int]) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param students int整型一维数组 * @param sandwiches int整型一维数组 * @return int整型 */ pub fn countStudents(&self, students: Vec
, sandwiches: Vec
) -> i32 { // write code here } }
[1,1,0,1],[1,0,0,1]
2