mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
Update C# code.
This commit is contained in:
@ -164,9 +164,9 @@ comments: true
|
||||
return 0;
|
||||
}
|
||||
|
||||
int algorithm(int n)
|
||||
{ // 输入数据
|
||||
int a = 0; // 暂存数据(常量)
|
||||
int algorithm(int n) // 输入数据
|
||||
{
|
||||
int a = 0; // 暂存数据(常量)
|
||||
int b = 0; // 暂存数据(变量)
|
||||
Node node = new Node(0); // 暂存数据(对象)
|
||||
int c = function(); // 栈帧空间(调用函数)
|
||||
@ -606,7 +606,7 @@ $$
|
||||
nodes = append(nodes, newNode(i))
|
||||
}
|
||||
// 长度为 n 的哈希表占用 O(n) 空间
|
||||
m := make(map[int]string, n)
|
||||
m := make(map[int]string, n)
|
||||
for i := 0; i < n; i++ {
|
||||
m[i] = strconv.Itoa(i)
|
||||
}
|
||||
@ -883,8 +883,8 @@ $$
|
||||
if n <= 0 {
|
||||
return 0
|
||||
}
|
||||
// 数组 nums 长度为 n, n-1, ..., 2, 1
|
||||
nums := make([]int, n)
|
||||
fmt.Printf("递归 n = %d 中的 nums 长度 = %d \n", n, len(nums))
|
||||
return spaceQuadraticRecur(n - 1)
|
||||
}
|
||||
```
|
||||
@ -914,8 +914,8 @@ $$
|
||||
int quadraticRecur(int n)
|
||||
{
|
||||
if (n <= 0) return 0;
|
||||
// 数组 nums 长度为 n, n-1, ..., 2, 1
|
||||
int[] nums = new int[n];
|
||||
Console.WriteLine("递归 n = " + n + " 中的 nums 长度 = " + nums.Length);
|
||||
return quadraticRecur(n - 1);
|
||||
}
|
||||
|
||||
|
||||
@ -103,7 +103,7 @@ $$
|
||||
int a = 2; // 1 ns
|
||||
a = a + 1; // 1 ns
|
||||
a = a * 2; // 10 ns
|
||||
// 循环 n 次
|
||||
// 循环 n 次
|
||||
for (int i = 0; i < n; i++)
|
||||
{ // 1 ns ,每轮都要执行 i++
|
||||
Console.WriteLine(0); // 5 ns
|
||||
@ -347,7 +347,7 @@ $$
|
||||
a = a * 2; // +1
|
||||
// 循环 n 次
|
||||
for (int i = 0; i < n; i++) { // +1(每轮都执行 i ++)
|
||||
Console.WriteLine(0); // +1
|
||||
Console.WriteLine(0); // +1
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -500,7 +500,7 @@ $$
|
||||
{
|
||||
int a = 1; // +0(技巧 1)
|
||||
a = a + n; // +0(技巧 1)
|
||||
// +n(技巧 2)
|
||||
// +n(技巧 2)
|
||||
for (int i = 0; i < 5 * n + 1; i++)
|
||||
{
|
||||
Console.WriteLine(0);
|
||||
@ -1422,7 +1422,7 @@ $$
|
||||
=== "C#"
|
||||
|
||||
```csharp title="time_complexity.cs"
|
||||
/* 对数阶(递归实现) */
|
||||
/* 对数阶(递归实现) */
|
||||
int logRecur(float n)
|
||||
{
|
||||
if (n <= 1) return 0;
|
||||
|
||||
Reference in New Issue
Block a user