1 #include <stack> 2 // you can write to stdout for debugging purposes, e.g. 3 // cout << "this is a debug message" << endl; 4 5 int solution(vector<int> &A, vector<int> &B) { 6 // write your code in C++11 7 stack<int> s; 8 int res = 0; 9 for(int i = 0 ; i < B.size() ; ++i) 10 { 11 if(B[i] == 0) 12 { 13 while(!s.empty()) 14 { 15 if(s.top() > A[i]) 16 { 17 break; 18 } 19 else 20 { 21 s.pop(); 22 } 23 } 24 if(s.empty()) 25 { 26 ++res; 27 } 28 } 29 else 30 { 31 s.push(A[i]); 32 } 33 } 34 res += s.size(); 35 return res; 36 }
转载于:https://www.cnblogs.com/cane/p/3977323.html