专业做网站费用,wordpress首页图片幻灯片播放,网站建设优化安徽,房产销售网站设计题目来源#xff1a; leetcode题目#xff0c;网址#xff1a;面试题 08.01. 三步问题 - 力扣#xff08;LeetCode#xff09;
解题思路#xff1a; 动态规划。1 阶楼梯 1 种走法#xff0c;2 阶楼梯 2 种走法#xff0c;3 阶楼梯 6 种类走法。假设有 n(n3) 阶…题目来源 leetcode题目网址面试题 08.01. 三步问题 - 力扣LeetCode
解题思路 动态规划。1 阶楼梯 1 种走法2 阶楼梯 2 种走法3 阶楼梯 6 种类走法。假设有 n(n3) 阶楼梯n-1 阶楼梯有 a 种走法n-2 阶楼梯有 b 种走法n-3 阶楼梯有 c 种走法则 n 阶楼梯有 abc 中走法。
解题代码
class Solution {public int waysToStep(int n) {if(n1){return 1;}else if(n2){return 2;}else if(n3){return 4;}else{return ways(n);}}public int ways(int n){long preThree1;long preTwo2;long preOne4;int now4;long respreOnepreTwopreThree;while(now!n){preThreepreTwo;preTwopreOne;preOneres;res(preOnepreTwopreThree)%1000000007;now;}return (int)res;}
} 总结 无官方题解。 staircase 楼梯