由买买提看人间百态

topics

全部话题 - 话题: getn
(共0页)
g***s
发帖数: 3811
1
来自主题: JobHunting版 - 问道amazon的面试题
public class FindSegments {
public static void main(String args[]) throws InterruptedException {
// List segs = Arrays.asList(new Integer[]{2, 3, 5, 7,
8, 10});
List segs = Arrays.asList(new Integer[]
{2,2,4,6,7,7,8,8,8,9,9,10,11,12,13,14,15,16,16,17,18,20,21,22,23,24,25,2
6,28,
29,30,31,33,34,37,38,39,40,41,45,47,47,49,54,56});
long startTime = System.currentTimeMillis();
findSegs(segs);
System.out.printf("Total running time : %d ms",... 阅读全帖
g***s
发帖数: 3811
2
来自主题: JobHunting版 - 问道amazon的面试题
public class FindSegments {
public static void main(String args[]) throws InterruptedException {
// List segs = Arrays.asList(new Integer[]{2, 3, 5, 7,
8, 10});
List segs = Arrays.asList(new Integer[]
{2,2,4,6,7,7,8,8,8,9,9,10,11,12,13,14,15,16,16,17,18,20,21,22,23,24,25,2
6,28,
29,30,31,33,34,37,38,39,40,41,45,47,47,49,54,56});
long startTime = System.currentTimeMillis();
findSegs(segs);
System.out.printf("Total running time : %d ms",... 阅读全帖
y***m
发帖数: 7027
3
来自主题: JobHunting版 - 问一题
f(1)=1
f(2)=2
f(n)=f(n-1)+f(n-2)
求所有大于0的整数f(n)值
弄了个数组从1..n挨个计算后把值存进去:
function Array getArray(n){
array a[n+1];
a[1]=1;
a[2]=2;
for(int i=3;i<=n;i++)
a[n]=a[n-1]+a[n-2];
return a;
}
function getN(n){
getArray(n)[n];
}
有更好的办法么
thx!
y***m
发帖数: 7027
4
来自主题: JobHunting版 - 问一题
数组解:
function Array getArray(n){
array a[n+1];
a[1]=1;
a[2]=2;
for(int i=3;i<=n;i++)
a[n]=a[n-1]+a[n-2];
return a;
}
function getN(n){
getArray(n)[n];
}

for
(共0页)