You are viewing a single comment's thread. Return to all comments →
clever! a slight modification would be to use new int[3] This gives us (O(1) space) and in the for loop you can replace
new int[3]
array[i] = array[i-1] + array[i-2] + array[i-3];
with
array[i % 3] = array[0] + array[1] + array[2];
to remain within bounds and return the value eventually.
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 →
clever! a slight modification would be to use
new int[3]
This gives us (O(1) space) and in the for loop you can replacewith
to remain within bounds and return the value eventually.