class Solution:
def __init__(self):
pass
def conflict(self, state, next_tuple):
if not state:
return False
if not next_tuple:
return True
for i in range(len(state)):
if (next_tuple[0] <= state[i][0] and next_tuple[1] > state[i][0]) or (next_tuple[0] >= state[i][0] and next_tuple[0] < state[i][1]):
return True
return False
def find_method(self, lst, array):
if not lst:
return array
array.append([lst[0]])
length = len(array)
for i in range(length):
if not self.conflict(array[i], lst[0]):
arr = array[i][:]
arr.append(lst[0])
array.append(arr)
self.find_method(lst[1:], array)
return array
def find_max(self, array):
max = 0
lst = []
#print("length of array= %d" % len(array))
for i in range(len(array)):
length = len(array[i])
if length > max:
max = length
lst = array[i]
print(max)
print(lst)
if __name__ == "__main__":
'''
array contain all alternative result
'''
so = Solution()
lst = [[0, 3], [3, 7], [7, 10]]
array = []
so.find_method(lst, array)
so.find_max(array)