diff --git a/docs/chapter_array_and_linkedlist/linked_list.md b/docs/chapter_array_and_linkedlist/linked_list.md index a7f163542..4b2053dc8 100755 --- a/docs/chapter_array_and_linkedlist/linked_list.md +++ b/docs/chapter_array_and_linkedlist/linked_list.md @@ -165,7 +165,7 @@ /* 链表节点类 */ // 构造方法 class ListNode(x: Int) { - val `val`: Int = x // 节点值 + val _val: Int = x // 节点值 val next: ListNode? = null // 指向下一个节点的引用 } ``` @@ -662,7 +662,7 @@ /* 双向链表节点类 */ // 构造方法 class ListNode(x: Int) { - val `val`: Int = x // 节点值 + val _val: Int = x // 节点值 val next: ListNode? = null // 指向后继节点的引用 val prev: ListNode? = null // 指向前驱节点的引用 } diff --git a/docs/chapter_computational_complexity/space_complexity.md b/docs/chapter_computational_complexity/space_complexity.md index 207881145..ab03ebcb5 100755 --- a/docs/chapter_computational_complexity/space_complexity.md +++ b/docs/chapter_computational_complexity/space_complexity.md @@ -312,7 +312,24 @@ === "Kotlin" ```kotlin title="" + /* 类 */ + class Node(var _val: Int) { + var next: Node? = null + } + + /* 函数 */ + fun function(): Int { + // 执行某些操作... + return 0 + } + fun algorithm(n: Int): Int { // 输入数据 + val a = 0 // 暂存数据(常量) + var b = 0 // 暂存数据(变量) + val node = Node(0) // 暂存数据(对象) + val c = function() // 栈帧空间(调用函数) + return a + b + c // 输出数据 + } ``` === "Zig" @@ -464,7 +481,13 @@ === "Kotlin" ```kotlin title="" - + fun algorithm(n: Int) { + val a = 0 // O(1) + val b = IntArray(10000) // O(1) + if (n > 10) { + val nums = IntArray(n) // O(n) + } + } ``` === "Zig" @@ -708,7 +731,21 @@ === "Kotlin" ```kotlin title="" - + fun function(): Int { + // 执行某些操作 + return 0 + } + /* 循环 O(1) */ + fun loop(n: Int) { + for (i in 0..