题解 | #跳台阶#
跳台阶
http://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4
dfs+HashMap剪枝
import java.util.*;
public class Solution {Map<Integer,Integer>memo=new HashMap<>();
public int jumpFloor(int target) {
if(target==0){
return 0;
}
return dfs(target);
}
int dfs(int target){
if(memo.containsKey(target)){
return memo.get(target);
}
if(target<0){
return 0;
}
else if(target==0){
return 1;
}
int res1=dfs(target-1);
int res2=dfs(target-2);
memo.put(target,res1+res2);
return res1+res2;
}
}