-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdp.py
More file actions
42 lines (31 loc) · 970 Bytes
/
dp.py
File metadata and controls
42 lines (31 loc) · 970 Bytes
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
def maxProfit(prices):
res = 0
profit = [[0 for i in range(3)] for i in range(len(prices))]
profit[0][0], profit[0][1], profit[0][2] = 0, -prices[0], 0
for i in range(1, len(prices)):
profit[i][0] = profit[i - 1][0]
profit[i][1] = max(profit[i - 1][1], profit[i-1][0] - prices[i])
profit[i][2] = profit[i - 1][1] + prices[i]
res = max(res, profit[i][1], profit[i][0], profit[i][2])
return res
prices = [7, 1, 5, 3, 6, 4]
temp = maxProfit(prices=prices)
# print(temp)
def findMinVal(arr):
minVal = arr[0]
minIndex = 0
for i, val in enumerate(arr):
if arr[i] < minVal:
minVal = arr[i]
minIndex = i
return minIndex
def selectSort(arr):
ret = []
for i in enumerate(arr):
minIndex = findMinVal(arr)
ret.append(arr.pop(minIndex))
return ret
arrList = [5, 3, 6, 2, 10]
print(selectSort([5, 3, 6, 2, 10]))
# arrList.pop(2)
# print(arrList)