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

Class Solution

Array/PartitionArrayIntoDisjointIntervals.py:58–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56
57"""
58class Solution(object):
59 def partitionDisjoint(self, A):
60 """
61 :type A: List[int]
62 :rtype: int
63 """
64 maxes = [A[0]]
65 mines = [A[-1]]
66
67 for i in range(1, len(A)):
68 if A[i] > maxes[i-1]:
69 maxes.append(A[i])
70 else:
71 maxes.append(maxes[i-1])
72
73 A = A[::-1]
74
75 for i in range(1, len(A)):
76
77 if A[i] < mines[i-1]:
78 mines.append(A[i])
79 else:
80 mines.append(mines[i-1])
81
82 mines = mines[::-1]
83 for i in range(len(mines)-1):
84 if maxes[i] <= mines[i+1]:
85 return i+1

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected