mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 09:21:13 +08:00
psf/black code formatting (#1277)
This commit is contained in:

committed by
Christian Clauss

parent
07f04a2e55
commit
9eac17a408
@ -1,32 +1,32 @@
|
||||
'''
|
||||
"""
|
||||
Auther : Yvonne
|
||||
|
||||
This is a pure Python implementation of Dynamic Programming solution to the longest_sub_array problem.
|
||||
|
||||
The problem is :
|
||||
Given an array, to find the longest and continuous sub array and get the max sum of the sub array in the given array.
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
class SubArray:
|
||||
|
||||
def __init__(self, arr):
|
||||
# we need a list not a string, so do something to change the type
|
||||
self.array = arr.split(',')
|
||||
self.array = arr.split(",")
|
||||
print(("the input array is:", self.array))
|
||||
|
||||
def solve_sub_array(self):
|
||||
rear = [int(self.array[0])]*len(self.array)
|
||||
sum_value = [int(self.array[0])]*len(self.array)
|
||||
rear = [int(self.array[0])] * len(self.array)
|
||||
sum_value = [int(self.array[0])] * len(self.array)
|
||||
for i in range(1, len(self.array)):
|
||||
sum_value[i] = max(int(self.array[i]) + sum_value[i-1], int(self.array[i]))
|
||||
rear[i] = max(sum_value[i], rear[i-1])
|
||||
return rear[len(self.array)-1]
|
||||
sum_value[i] = max(
|
||||
int(self.array[i]) + sum_value[i - 1], int(self.array[i])
|
||||
)
|
||||
rear[i] = max(sum_value[i], rear[i - 1])
|
||||
return rear[len(self.array) - 1]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
whole_array = input("please input some numbers:")
|
||||
array = SubArray(whole_array)
|
||||
re = array.solve_sub_array()
|
||||
print(("the results is:", re))
|
||||
|
||||
|
Reference in New Issue
Block a user