Skip to content

Commit

Permalink
#28 메서드 응용 - 재귀
Browse files Browse the repository at this point in the history
  • Loading branch information
guddus326 committed Jul 2, 2021
1 parent 8e597c1 commit 8c3d1a6
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions CSBasic5/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;

namespace CSBasic5
{
Expand Down Expand Up @@ -224,6 +225,8 @@ static void Main(string[] args)
t.value = 30;
TestSome.change(t);
Console.WriteLine(t.value);

Console.WriteLine(Fibonacci.Get(10000));
}


Expand All @@ -242,5 +245,27 @@ public static void change(TestSome input)

}
}
class Fibonacci
{
private static Dictionary<int, long> memo = new Dictionary<int, long>();
public static int count = 0;
public static long Get(int i)
{
count++;
Console.WriteLine(count);
if (i < 0) { return 0; }
if (i ==1) { return 1; }
if (memo.ContainsKey(i))
{
return memo[i];
}
else
{
memo[i] = Get(i - 2) + Get(i - 1);
return memo[i];
}

}
}

}

0 comments on commit 8c3d1a6

Please sign in to comment.