[Solved] I wonder what is exact meaning of “return”


The i < 0 and i == 1 lines do not use the dictionary at all. For those early terms, the dictionary lookup would be slower than the calculation anyway.

The if (memo.ContainsKey(i)) { return memo[i]; } line also does not set anything new in the dictionary. It reads from the dictionary, but does not write to it, because either the value is already there or we don’t know what to write yet. Today, I might update this code to use TryGetValue() instead, in order to save one hash calculation and lookup on success.

The line that actually writes to the dictionary is this:

memo[i] = value;

Additionally, the reason the dictionary is named memo is because the code uses a technique called memoization.

2

solved I wonder what is exact meaning of “return”