File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed
Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ void main() {
1111
1212// Tabulation (Bottom-up approach in Dynamic Programming) (usually done using iteration).
1313// Time Complexity: O(n), and better Auxiliary Space.
14- fibTabulated (int n) {
14+ int fibTabulated (int n) {
1515 if (n <= 0 ) throw ArgumentError ('Input must be a positive integer' );
1616
1717 final table = [1 , 1 ];
@@ -27,10 +27,10 @@ fibTabulated(int n) {
2727
2828// Memoization (Top-down approach in Dynamic Programming) (usually involves recursion).
2929// Time Complexity: O(n)
30- fibMemoized (int n) {
30+ int fibMemoized (int n) {
3131 if (n <= 0 ) throw ArgumentError ('Input must be a positive integer' );
3232 if (n <= 2 ) return 1 ;
33- if (_memo.containsKey (n)) return _memo[n];
33+ if (_memo.containsKey (n)) return _memo[n]! ;
3434
3535 final result = fibMemoized (n - 1 ) + fibMemoized (n - 2 );
3636 _memo[n] = result;
@@ -44,7 +44,7 @@ final Map<int, int> _memo = {};
4444// https://i.stack.imgur.com/kgXDS.png
4545// Note: it's exactly (1.6180339887^n), which is known as the golden ratio:
4646// https://stackoverflow.com/questions/360748
47- fibRecursive (int n) {
47+ int fibRecursive (int n) {
4848 if (n <= 0 ) throw ArgumentError ('Input must be a positive integer' );
4949 if (n <= 2 ) return 1 ;
5050
You can’t perform that action at this time.
0 commit comments