:type A: List[int] :rtype: bool
(self, A)
| 34 | |
| 35 | class Solution(object): |
| 36 | def isIdealPermutation(self, A): |
| 37 | """ |
| 38 | :type A: List[int] |
| 39 | :rtype: bool |
| 40 | """ |
| 41 | global_inversions = [] |
| 42 | _g = 0 |
| 43 | |
| 44 | for i in A[::-1]: |
| 45 | _g += bisect.bisect_left(global_inversions, i) |
| 46 | bisect.insort_left(global_inversions, i) |
| 47 | |
| 48 | _l = 0 |
| 49 | |
| 50 | for i in range(len(A)-1): |
| 51 | if A[i] > A[i+1]: |
| 52 | _l += 1 |
| 53 | |
| 54 | return _g == _l |
| 55 |
nothing calls this directly
no outgoing calls
no test coverage detected