静态链表
class Solution { public: int countStudents(vector<int>& students, vector<int>& sandwiches) { int stup = 0,sanp = 0,tmp; int n = students.size(),cnt = 0,n2 = n,tail = n-1; int a[105]; bool flag = false; for(int i=0;i<n;i++){ a[i] = i+1; } a[n-1] = -1; while(true){ if(students[stup]==sandwiches[sanp]){ stup=a[stup]; sanp++; cnt = 0; n2--; if(n2==0)break; }else{ cnt++; if(cnt==n2){ break; } tmp = a[stup]; a[tail] = stup; a[stup] = -1; tail = stup; stup = tmp; } } return n2; } };
标签:false,int,leetcode1700,链表,students,vector From: https://www.cnblogs.com/stevenzrx/p/17240012.html