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
int maxV = A[0];
for(int i = 2; i < A.size(); i++){
if(A[i] < maxV){
return false;
}
maxV = max(maxV, A[i - 2]);
}
return true;
}
};
Comments
Post a Comment