mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-25 01:27:13 +00:00
feat(csharp) .NET 8.0 code migration (#966)
* .net 8.0 migration * update docs * revert change * revert change and update appendix docs * remove static * Update binary_search_insertion.cs * Update binary_search_insertion.cs * Update binary_search_edge.cs * Update binary_search_insertion.cs * Update binary_search_edge.cs --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@@ -8,7 +8,7 @@ namespace hello_algo.chapter_greedy;
|
||||
|
||||
public class coin_change_greedy {
|
||||
/* 零钱兑换:贪心 */
|
||||
public int CoinChangeGreedy(int[] coins, int amt) {
|
||||
int CoinChangeGreedy(int[] coins, int amt) {
|
||||
// 假设 coins 列表有序
|
||||
int i = coins.Length - 1;
|
||||
int count = 0;
|
||||
@@ -29,14 +29,14 @@ public class coin_change_greedy {
|
||||
[Test]
|
||||
public void Test() {
|
||||
// 贪心:能够保证找到全局最优解
|
||||
int[] coins = { 1, 5, 10, 20, 50, 100 };
|
||||
int[] coins = [1, 5, 10, 20, 50, 100];
|
||||
int amt = 186;
|
||||
int res = CoinChangeGreedy(coins, amt);
|
||||
Console.WriteLine("\ncoins = " + coins.PrintList() + ", amt = " + amt);
|
||||
Console.WriteLine("凑到 " + amt + " 所需的最少硬币数量为 " + res);
|
||||
|
||||
// 贪心:无法保证找到全局最优解
|
||||
coins = new int[] { 1, 20, 50 };
|
||||
coins = [1, 20, 50];
|
||||
amt = 60;
|
||||
res = CoinChangeGreedy(coins, amt);
|
||||
Console.WriteLine("\ncoins = " + coins.PrintList() + ", amt = " + amt);
|
||||
@@ -44,7 +44,7 @@ public class coin_change_greedy {
|
||||
Console.WriteLine("实际上需要的最少数量为 3 ,即 20 + 20 + 20");
|
||||
|
||||
// 贪心:无法保证找到全局最优解
|
||||
coins = new int[] { 1, 49, 50 };
|
||||
coins = [1, 49, 50];
|
||||
amt = 98;
|
||||
res = CoinChangeGreedy(coins, amt);
|
||||
Console.WriteLine("\ncoins = " + coins.PrintList() + ", amt = " + amt);
|
||||
|
||||
Reference in New Issue
Block a user