File tree 1 file changed +12
-8
lines changed
1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change 1
1
# Time: O(n)
2
2
# Space: O(1)
3
3
4
- class Solution :
5
- # @param {integer[][]} costs
6
- # @return {integer}
4
+ class Solution (object ):
7
5
def minCost (self , costs ):
6
+ """
7
+ :type costs: List[List[int]]
8
+ :rtype: int
9
+ """
8
10
if not costs :
9
11
return 0
10
12
@@ -19,14 +21,16 @@ def minCost(self, costs):
19
21
min_cost [i % 2 ][2 ] = costs [i ][2 ] + \
20
22
min (min_cost [(i - 1 ) % 2 ][0 ], min_cost [(i - 1 ) % 2 ][1 ])
21
23
22
- return min (min_cost [(n - 1 ) % 2 ][ 0 ], min_cost [( n - 1 ) % 2 ][ 1 ], min_cost [( n - 1 ) % 2 ][ 2 ] )
24
+ return min (min_cost [(n - 1 ) % 2 ])
23
25
24
26
# Time: O(n)
25
27
# Space: O(n)
26
- class Solution2 :
27
- # @param {integer[][]} costs
28
- # @return {integer}
28
+ class Solution2 (object ):
29
29
def minCost (self , costs ):
30
+ """
31
+ :type costs: List[List[int]]
32
+ :rtype: int
33
+ """
30
34
if not costs :
31
35
return 0
32
36
@@ -36,4 +40,4 @@ def minCost(self, costs):
36
40
costs [i ][1 ] += min (costs [i - 1 ][0 ], costs [i - 1 ][2 ])
37
41
costs [i ][2 ] += min (costs [i - 1 ][0 ], costs [i - 1 ][1 ])
38
42
39
- return min (costs [n - 1 ][ 0 ], costs [ n - 1 ][ 1 ], costs [ n - 1 ][ 2 ] )
43
+ return min (costs [n - 1 ])
You can’t perform that action at this time.
0 commit comments