Skip to content

Commit

Permalink
Fibonacci Number
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthDhavan04 authored May 23, 2024
1 parent 5ccc729 commit 25d9f28
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Problem 509.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public int fib(int n) {
int a=1;
int b=0;
int sum=0;

if(n==0){
return 0;
}
else if(n==1){
return 1;
}
else{
for(int i=2 ;i<=n ;i++){
sum=b+a;
b=a;
a=sum;
}
return sum;
}
}
}

0 comments on commit 25d9f28

Please sign in to comment.