MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / isIdealPermutation

Method isIdealPermutation

Array/GlobalAndLocalInversions.py:36–54  ·  view source on GitHub ↗

:type A: List[int] :rtype: bool

(self, A)

Source from the content-addressed store, hash-verified

34
35class 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected