Reputation: 1
Here is my code. It's not work...Anyone can help me?
map<int,int> fibo;
int fibonacci( int n )
{
if ( n == 0 || n == 1 )
return 1;
map<int,int>::iterator itr = fibo.find( n );
if ( itr != fibo.end() )
return itr->second;
else
return fibo[ n ] = fibonacci( n -1 ) + fibonacci( n - 2 );
}
i've solved this. Here's the Sample Solution!
Upvotes: 0
Views: 846
Reputation: 70472
You are checking for end()
against the wrong container. Presumably, results
is another instance of a map<int,int>
.
Change results
to fibo
:
if ( itr != fibo.end() )
Upvotes: 1