-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_array_ranges.py
50 lines (38 loc) · 1.16 KB
/
1_array_ranges.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class Range:
low = 0
high = 0
def __init__(self, n):
self.low=self.high=n
def __str__(self):
return "(%s, %s)" % (self.low, self.high)
def solution(A):
data = [Range(0)]
for n in A:
print(" >>> %s " % n)
if n < 1:
continue
action = False
for d in range(len(data)):
if data[d].low <= n and data[d].high >= n:
print("absorbed")
action = True
if data[d].high == n-1:
print("enlarging")
action = True
data[d].high = n
if data[d].low > n:
data.insert(d, Range(n))
print("inserting")
action = True
if len(data) > d+1 and data[d+1].low == n+1:
data[d].high=data[d+1].high
del data[d+1]
print("connecting")
if action:
break
if not action:
data.append(Range(n))
print("appending")
for d in data:
print(d)
return data[0].high + 1