This commit is contained in:
krahets
2023-11-27 02:32:06 +08:00
parent 32d5bd97aa
commit a4a23e2488
31 changed files with 179 additions and 213 deletions

View File

@@ -104,10 +104,9 @@ comments: true
```csharp title=""
/* 类 */
class Node {
int val;
class Node(int x) {
int val = x;
Node next;
Node(int x) { val = x; }
}
/* 函数 */
@@ -119,7 +118,7 @@ comments: true
int Algorithm(int n) { // 输入数据
const int a = 0; // 暂存数据(常量)
int b = 0; // 暂存数据(变量)
Node node = new(0); // 暂存数据(对象)
Node node = new(0); // 暂存数据(对象)
int c = Function(); // 栈帧空间(调用函数)
return a + b + c; // 输出数据
}
@@ -1123,12 +1122,12 @@ $$
// 长度为 n 的数组占用 O(n) 空间
int[] nums = new int[n];
// 长度为 n 的列表占用 O(n) 空间
List<ListNode> nodes = new();
List<ListNode> nodes = [];
for (int i = 0; i < n; i++) {
nodes.Add(new ListNode(i));
}
// 长度为 n 的哈希表占用 O(n) 空间
Dictionary<int, string> map = new();
Dictionary<int, string> map = [];
for (int i = 0; i < n; i++) {
map.Add(i, i.ToString());
}
@@ -1524,9 +1523,9 @@ $$
// 矩阵占用 O(n^2) 空间
int[,] numMatrix = new int[n, n];
// 二维列表占用 O(n^2) 空间
List<List<int>> numList = new();
List<List<int>> numList = [];
for (int i = 0; i < n; i++) {
List<int> tmp = new();
List<int> tmp = [];
for (int j = 0; j < n; j++) {
tmp.Add(0);
}

View File

@@ -2338,7 +2338,7 @@ $$
int Logarithmic(float n) {
int count = 0;
while (n > 1) {
n = n / 2;
n /= 2;
count++;
}
return count;