diff --git a/src/main/java/com/cool/hot100/dp/Num118.java b/src/main/java/com/cool/hot100/dp/Num118.java new file mode 100644 index 0000000..946030f --- /dev/null +++ b/src/main/java/com/cool/hot100/dp/Num118.java @@ -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> generate(int numRows) { + List> res=new ArrayList<>(); + for(int i=0;i list=new ArrayList<>(); + for(int j=0;j<=i;j++){ + if(j==0||j==i){ + list.add(1); + }else{ + List temp=res.get(i-1); + list.add(temp.get(j)+temp.get(j-1)); + } + } + res.add(list); + } + return res; + } + +} diff --git a/src/main/java/com/cool/hot100/dp/Num70.java b/src/main/java/com/cool/hot100/dp/Num70.java new file mode 100644 index 0000000..6813f61 --- /dev/null +++ b/src/main/java/com/cool/hot100/dp/Num70.java @@ -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; + } +}