leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 1b4d966bb21f22db7d514e8401e8427282c6333b
parent 12b654c7aff45628bd062f355bb31f1ebf7ae5bc
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Fri, 12 May 2023 13:48:36 -0500

Completed fibonacci number problem using C++

Diffstat:
Afibonacci-number/fibonacci-number.cpp | 13+++++++++++++
1 file changed, 13 insertions(+), 0 deletions(-)

diff --git a/fibonacci-number/fibonacci-number.cpp b/fibonacci-number/fibonacci-number.cpp @@ -0,0 +1,13 @@ +//Find the nth value in the fibonacci number sequence. +//I did this recursively with a time complexity of O(n). +//Time: 11ms Beats: 47.1% +//Memory: 5.9MB Beats: 94.32% +class Solution { +public: + int fib(int n) { + if(n <= 1){ + return n; + } + return fib(n - 1) + fib(n - 2); + } +};