题解 | #跳台阶#

跳台阶

http://www.nowcoder.com/practice/bfb2a2b3cdbd4bd6bba0d4dca69aa3f0

import java.util.; import java.io.; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str = null; while((str = in.readLine())!= null){ int n = Integer.parseInt(str); if(n == 1){ System.out.println(1); continue; } if(n == 2){ System.out.println(2); continue; } int pre = 1; int post = 2; int dest = 0; int i = 3; while(i <= n){ dest = pre + post; pre = post; post = dest; i ++; } System.out.println(dest); } } // public static int clip(int n){ // if(n == 1) return 1; // if(n == 2) return 2; // return clip(n - 1)+clip(n-2); // } }

我居南半坡 文章被收录于专栏

多刷题,积蓄力量,欢迎讨论

全部评论
没有可读性
点赞 回复
分享
发布于 2022-11-16 14:08 山东

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务