FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/code/lc746.java at master · mJackie/leetcode · GitHub
mJackie
/
leetcode
Public
Notifications
You must be signed in to change notification settings
Fork
135
Star
405
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode
/
code
/
lc746.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
21 lines (21 loc) · 599 Bytes
Breadcrumbs
leetcode
/
code
/
lc746.java
Copy path
File metadata and controls
21 lines (21 loc) · 599 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package
code
;
/*
* 746. Min Cost Climbing Stairs
* 题意:上楼梯,变了一下形
* 难度:Easy
* 分类:Array, Dynamic Programming
* 思路:
* Tips:Bingo!
*/
public
class
lc746
{
public
int
minCostClimbingStairs
(
int
[]
cost
) {
if
(
cost
.
length
==
1
)
return
cost
[
0
];
int
dp1
=
cost
[
0
],
dp2
=
cost
[
1
],
dp3
=
Integer
.
MAX_VALUE
;
for
(
int
i
=
2
;
i
<
cost
.
length
;
i
++){
dp3
=
Math
.
min
(
dp1
+
cost
[
i
],
dp2
+
cost
[
i
]);
dp1
=
dp2
;
dp2
=
dp3
;
}
return
Math
.
min
(
dp1
,
dp2
);
//注意下返回值,还要比较一下
}
}
Back
|
FazBrowse Home
|
New Git URL