首页 > 其他分享 >leetcode1700

leetcode1700

时间:2023-03-21 15:03:07浏览次数:41  
标签:false int leetcode1700 链表 students vector

静态链表

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

相关文章