题解 | #删除链表的节点#
跳台阶
http://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4
参考C++,引入一个map,避免重复计算 将已经计算的值保存到map中,计算的时候直接查询map, 有就直接返回值,没有就存入map,并返回值
import java.util.*;
public class Solution {
//记忆搜索
HashMap<Integer,Integer> map=new HashMap<>();//保存已经被计算的值
public int jumpFloor(int target) {
if(target<=2){
return target;
}
//获取已保存的值
if(map.containsKey(target)){
return map.get(target);
}
//存入未有的值,并返回
map.put(target,jumpFloor(target-1)+jumpFloor(target-2));
return map.get(target);
}
}