mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-05 11:41:22 +08:00
fix(csharp): reformat csharp codes and docs (#652)
* fix(csharp): reformat the C# codes and docs * Update time_complexity.md --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@@ -45,7 +45,7 @@ public class list {
|
||||
|
||||
/* 通过索引遍历列表 */
|
||||
int count = 0;
|
||||
for (int i = 0; i < list.Count(); i++) {
|
||||
for (int i = 0; i < list.Count; i++) {
|
||||
count++;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ class MyList {
|
||||
/* 列表扩容 */
|
||||
public void extendCapacity() {
|
||||
// 新建一个长度为 numsCapacity * extendRatio 的数组,并将原数组拷贝到新数组
|
||||
System.Array.Resize(ref nums, numsCapacity * extendRatio);
|
||||
Array.Resize(ref nums, numsCapacity * extendRatio);
|
||||
// 更新列表容量
|
||||
numsCapacity = nums.Length;
|
||||
}
|
||||
|
||||
@@ -87,9 +87,7 @@ public class time_complexity {
|
||||
for (int j = 0; j < i; j++) {
|
||||
if (nums[j] > nums[j + 1]) {
|
||||
// 交换 nums[j] 与 nums[j + 1]
|
||||
int tmp = nums[j];
|
||||
nums[j] = nums[j + 1];
|
||||
nums[j + 1] = tmp;
|
||||
(nums[j + 1], nums[j]) = (nums[j], nums[j + 1]);
|
||||
count += 3; // 元素交换包含 3 个单元操作
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class two_sum {
|
||||
return new int[] { i, j };
|
||||
}
|
||||
}
|
||||
return new int[0];
|
||||
return Array.Empty<int>();
|
||||
}
|
||||
|
||||
/* 方法二:辅助哈希表 */
|
||||
@@ -32,7 +32,7 @@ public class two_sum {
|
||||
}
|
||||
dic.Add(nums[i], i);
|
||||
}
|
||||
return new int[0];
|
||||
return Array.Empty<int>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -29,11 +29,11 @@ public class queue {
|
||||
Console.WriteLine("出队元素 pop = " + pop + ",出队后 queue = " + string.Join(",", queue));
|
||||
|
||||
/* 获取队列的长度 */
|
||||
int size = queue.Count();
|
||||
int size = queue.Count;
|
||||
Console.WriteLine("队列长度 size = " + size);
|
||||
|
||||
/* 判断队列是否为空 */
|
||||
bool isEmpty = queue.Count() == 0;
|
||||
bool isEmpty = queue.Count == 0;
|
||||
Console.WriteLine("队列是否为空 = " + isEmpty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ public class stack {
|
||||
Console.WriteLine("出栈元素 pop = " + pop + ",出栈后 stack = " + string.Join(",", stack));
|
||||
|
||||
/* 获取栈的长度 */
|
||||
int size = stack.Count();
|
||||
int size = stack.Count;
|
||||
Console.WriteLine("栈的长度 size = " + size);
|
||||
|
||||
/* 判断是否为空 */
|
||||
bool isEmpty = stack.Count() == 0;
|
||||
bool isEmpty = stack.Count == 0;
|
||||
Console.WriteLine("栈是否为空 = " + isEmpty);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user