You are viewing a single comment's thread. Return to all comments →
Java linear solution:
public static int calcWays(int n) { if (n < 1) return 0; if (n == 1) return 1; if (n == 2) return 2; if (n == 3) return 4; int[] ways = new int[] {1,2,4}; for (int i = 4; i < n; i++) { int idx = (i - 1) % 3; ways[idx] = ways[0] + ways[1] + ways[2]; } return ways[0] + ways[1] + ways[2]; }
Seems like cookies are disabled on this browser, please enable them to open this website
Recursion: Davis' Staircase
You are viewing a single comment's thread. Return to all comments →
Java linear solution: