AM 1037. Global and Local Inversions

class Solution { public: /** * @param A: an array * @return: is the number of global inversions is equal to the number of local inversions */ bool isIdealPermutation(vector<int> &A) { // Write your code here // lacal is also global. But global with more than 1 interval is not local; int maxV = A[0]; for(int i = 2; i < A.size(); i++){ if(maxV > A[i]){ return false; } maxV = A[i - 2]; } return true; } };

Comments

Popular posts from this blog

算法的比较