2024/9/23 LeetCode Hot100 dp
This commit is contained in:
parent
feda21c8d6
commit
70decfdfba
|
@ -0,0 +1,34 @@
|
|||
package com.cool.hot100.dp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
*
|
||||
* @Author: Cool
|
||||
* @Date: 2024/09/23/22:34
|
||||
* DayNumber 4
|
||||
* Hard 1
|
||||
* Level 3
|
||||
*/
|
||||
public class Num118 {
|
||||
|
||||
public List<List<Integer>> generate(int numRows) {
|
||||
List<List<Integer>> res=new ArrayList<>();
|
||||
for(int i=0;i<numRows;i++){
|
||||
List<Integer> list=new ArrayList<>();
|
||||
for(int j=0;j<=i;j++){
|
||||
if(j==0||j==i){
|
||||
list.add(1);
|
||||
}else{
|
||||
List<Integer> temp=res.get(i-1);
|
||||
list.add(temp.get(j)+temp.get(j-1));
|
||||
}
|
||||
}
|
||||
res.add(list);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.cool.hot100.dp;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
*
|
||||
* @Author: Cool
|
||||
* @Date: 2024/09/23/22:19
|
||||
* DayNumber 3
|
||||
* Hard 1
|
||||
* Level 2
|
||||
*/
|
||||
public class Num70 {
|
||||
public int climbStairs(int n) {
|
||||
if (n <= 2) {
|
||||
return n;
|
||||
}
|
||||
int num1 = 1;
|
||||
int num2 = 2;
|
||||
int res = 0;
|
||||
for (int i = 3; i <= n; i++) {
|
||||
res = num1 + num2;
|
||||
num1=num2;
|
||||
num2=res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue