public class Solution { public int JumpFloor(int target) { if(target < 1){ return 0; } if(target < 3){ return target; } /** 1: 1 2: 2 3: 1 + 2 = 3; */ int a = 1; int b = 2; for(int i = 3; i <= target; i++){ b = a + b; a = b - a; } return b; } }
public class Solution { public int JumpFloor(int target) { if(target < 1){ return 0; } if(target < 3){ return target; } /** 1: 1 2: 2 3: 1 + 2 = 3; */ int a = 1; int b = 2; for(int i = 3; i <= target; i++){ b = a + b; a = b - a; } return b; } }