We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicstaticStringisFibo(longn){if(isFibo(n,0,1))return"IsFibo";return"IsNotFibo";}privatestaticbooleanisFibo(longn,longfirst,longsecond){// Basecase: checking if the sum of f(n-1) + f(n-2)// Return false if Sum is larger than N// Return true if Sum is Nlongsum=first+second;if(sum==n)returntrue;if(sum>n)returnfalse;// Recursive call returnisFibo(n,second,sum);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Is Fibo
You are viewing a single comment's thread. Return to all comments →
This is my Java 8 solution, feel free to ask me any questions.
Solution 1:
Solution 2: