lintcode-跳跃游戏
folute_
这个作者很懒,什么都没留下…
展开
-
LintCode Java——丑数
设计一个算法,找出只含素因子2,3,5 的第 n 小的数。符合条件的数如:1, 2, 3, 4, 5, 6, 8, 9, 10, 12…注意事项 我们可以认为1也是一个丑数样例 如果n = 9, 返回 10public int nthUglyNumber(int n) { // write your code here int[] ...原创 2017-11-27 11:09:43 · 684 阅读 · 0 评论 -
LintCode Java——斐波纳契数列
查找斐波纳契数列中第 N 个数。所谓的斐波纳契数列是指:前2个数是 0 和 1 。 第 i 个数是第 i-1 个数和第i-2 个数的和。 斐波纳契数列的前10个数字是:0, 1, 1, 2, 3, 5, 8, 13, 21, 34 …public int fibonacci(int n) { // write your code here ...原创 2017-10-29 21:23:17 · 254 阅读 · 0 评论 -
LintCode Java——尾部的零
设计一个算法,计算出n阶乘中尾部零的个数public long trailingZeros(long n) { // write your code here, try to do it without arithmetic operators. long count = 0; long temp = n/5; while(t...原创 2017-10-27 11:56:22 · 645 阅读 · 2 评论 -
LintCode Java——A + B 问题
给出两个整数a和b, 求他们的和, 但不能使用 + 等数学运算符。public int aplusb(int a, int b) { // write your code here if((a&b)==0){ return a^b; }else{ return aplusb(a^b,(...原创 2017-10-26 13:05:39 · 470 阅读 · 2 评论