Global and Local Inversions


  • 0
    L

    class Solution {
    public boolean isIdealPermutation(int[] A) {
    boolean flag = true;
    for(int i =0;i<A.length;i++){
    int j = i+2;
    while(j<A.length){
    if(A[i]>A[j]){
    flag = false;
    return flag;
    }
    else {
    j++;
    }
    }
    }
    return flag;
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.