我在leetcode上写过类似的题,这个代码在xdoj上只能得***50***分,跪求各位大佬挑挑毛病。
#include<stack>
#include<iostream>
#include<vector>
using namespace std;
int main(){vector<int>poped;stack<int>s;int n,t;cin>>n;int n1=n;while(n1--){cin>>t;poped.push_back(t);}int index=0;for(int i=1;i<=n;++i){s.push(i);while(!s.empty()&&s.top()==poped[index]){s.pop();++index;}}if(s.empty()) cout<<"yes";else cout<<"no";return 0;}
END