点滴记录--递归
来源:互联网 发布:网络监控安装步骤图解 编辑:程序博客网 时间:2024/05/01 10:21
最近没多少事,准备面试,看到递归,一个很简单的递归。豁然间发现不会了,于是翻以前的代码,找到瞄了下,记录在此,记性不好,免得又忘。
递归计算 1 1 2 3 5 8 。。。。n
第N位的数,或者N位的和加。
public static class Recursion
{
//N位数值
public static int RecursionIndex(int index)
{
if (index == 1 || index == 2)
{
return 1;
}
else
{
return RecursionIndex(index - 2) + RecursionIndex(index - 1);
}
}
public static int RecursionCount(int index)
{
//N位累加和
if (index == 1)
{
return 1;
}
else if (index == 2)
{
return 2;
}
else
{
//得到当前数值后往回推,直到1
return RecursionCount(index - 1) + RecursionIndex(index);
}
}
}
谨以此告诫自己记录生活点滴,脑子记不住了就要手勤快点。
- 点滴记录--递归
- 记录点滴
- 点滴记录
- 记录点滴
- 点滴记录
- 记录点滴
- 点滴记录
- 记录点滴
- 记录点滴
- 记录点滴
- 记录点滴
- 记录点滴
- 点滴记录。
- 记录点滴
- 记录点滴
- 记录点滴
- 记录点滴
- 点滴记录
- ultraedit 正则表达式 -删除包含某个字符串的所有行 .
- lua的函数的环境和变量
- have a look!
- 《干货集锦》——前端大牛 Addy Osmani 的15个精彩PPT
- Linux平台代码覆盖率测试工具gcov简介
- 点滴记录--递归
- 调整导航条上leftBarButtonItem和rightBarButtonItem与屏幕边界的间距
- 15个HTML5的初级技巧
- addslashes与mysql_real_escape_string的区别
- 程序员学习能力提升三要素
- Eclipse/MyEclipse 快捷键
- 移动应用软件开发--人员角色定位和分工
- 一个苦逼的时期!
- Android Download: unexpected end of stream