Update C# code.

This commit is contained in:
Yudong Jin
2022-12-24 17:05:58 +08:00
parent 4906021ccb
commit 8733557f00
16 changed files with 88 additions and 118 deletions

View File

@ -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);
}

View File

@ -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;