File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
0123.Best Time to Buy and Sell Stock III Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def maxProfit (self , prices : List [int ]) -> int :
3
+ length = len (prices )
4
+ if 0 == length :
5
+ return 0
6
+ dp = [([0 ] * length ) for i in range (3 )]
7
+ for i in range (1 , 3 , 1 ):
8
+ maxdiff = - ((1 << 31 ) - 1 )
9
+ for j in range (1 , length , 1 ):
10
+ maxdiff = max (maxdiff , dp [i - 1 ][j - 1 ] - prices [j - 1 ])
11
+ dp [i ][j ] = max (dp [i ][j - 1 ], maxdiff + prices [j ])
12
+ return dp [2 ][length - 1 ]
Original file line number Diff line number Diff line change 488
488
├── 0123.Best Time to Buy and Sell Stock III
489
489
│ ├── README.md
490
490
│ ├── Solution.cpp
491
- │ └── Solution.java
491
+ │ ├── Solution.java
492
+ │ └── Solution.py
492
493
├── 0124.Binary Tree Maximum Path Sum
493
494
│ └── Solution.java
494
495
├── 0125.Valid Palindrome
You can’t perform that action at this time.
0 commit comments