xxxxxxxxxx
class Solution86
{
//Function to find the nth fibonacci number using top-down approach.
public long findNthFibonacci(int number, long dp[])
{ if (number == 0){
dp [number]=0;
return dp [number];
}
else if (number == 1){
dp [number]=1;
return dp [number];
}
else if (dp[number] != 0){
return dp [number];
}else {
dp [number]=findNthFibonacci(number-1,dp)+findNthFibonacci(number-2,dp);
return dp [number];
}
}
}