剑指Offer——网易笔试题+知识点总结
【摘要】 剑指Offer——网易笔试题+知识点总结
Fibonacci
package cn.edu.ujn.nk;
import java.util.ArrayList;
import java.util.Scanner;
/**
* 费波纳茨数
* @author SHQ
*
*/
public class Finonacci { /** * @param...
剑指Offer——网易笔试题+知识点总结
Fibonacci
package cn.edu.ujn.nk;
import java.util.ArrayList;
import java.util.Scanner;
/**
* 费波纳茨数
* @author SHQ
*
*/
public class Finonacci { /** * @param args */ public static void main(String[] args) {
// System.out.println(fibonacci(30)); Scanner in = new Scanner(System.in); while(in.hasNextInt()){ int a = in.nextInt(); System.out.println(fibonacci(a)); } } private static int fibonacci(int target){ ArrayList<Integer> arr = new ArrayList<Integer>(); int min = 0; int max = 0; arr.add(0, 0); arr.add(1, 1); for(int i = 2; i < target; i++){ arr.add(i, arr.get(i-1)+arr.get(i-2)); if(arr.get(i) >= target){ min = target - arr.get(i-1); max = arr.get(i) - target; break; } } return min > max ? max : min; }
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
数字游戏
幸运的袋子
简答题
Java开发中如何防止内存泄漏?
文章来源: shq5785.blog.csdn.net,作者:No Silver Bullet,版权归原作者所有,如需转载,请联系作者。
原文链接:shq5785.blog.csdn.net/article/details/53163703
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)