I believe this solution does run in a linear fashion, 1 additional calculation for each step added. But I can not get this task to pass the last criteria. Any help?
package com.codegym.task.task39.task3904;
import org.apache.commons.collections4.functors.PredicateTransformer;
import java.util.Arrays;
/*
Stairs
*/
public class Solution {
private static int n = 70;
public static void main(String[] args) {
System.out.println("The number of possible ascents for " + n + " steps is: " + numberOfPossibleAscents(n));
}
public static long numberOfPossibleAscents(int n) {
if (n < 0) return 0;
if (n == 0) return 1;
if (n == 1) return 1;
int[] res = new int[n + 1];
res[0] = 1;
res[1] = 1;
res[2] = 2;
for (int i = 3; i <= n; i++)
res[i] = res[i - 1] + res[i - 2]
+ res[i - 3];
return res[n];
}
}