Simplify kotlin code and improve code readability (#1198)

* Add kotlin code block for chapter_hashing

* Add kotlin code block for chapter_heap.

* Add kotlin code block for chapter_stack_and_queue and chapter_tree

* fix indentation

* Update binary_tree.md

* style(kotlin): simplify code and improve readability.

* simplify kt code for chapter_computational_complexity.

* style(kotlin): replace ArrayList with MutableList.

* Update subset_sum_i.kt

Use kotlin api instead of java.

* Update subset_sum_ii.kt

use kotlin api instead of java

* style(kotlin): replace ArrayList with mutablelist.

---------

Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
curtishd
2024-04-07 01:31:58 +08:00
committed by GitHub
parent 931d8f5089
commit 2655a2f66a
17 changed files with 101 additions and 101 deletions
@@ -10,7 +10,7 @@ import utils.TreeNode
import utils.printTree
var path: MutableList<TreeNode>? = null
var res: MutableList<List<TreeNode>>? = null
var res: MutableList<MutableList<TreeNode>>? = null
/* 前序遍历:例题三 */
fun preOrder(root: TreeNode?) {
@@ -22,7 +22,7 @@ fun preOrder(root: TreeNode?) {
path!!.add(root)
if (root.value == 7) {
// 记录解
res!!.add(ArrayList(path!!))
res!!.add(path!!.toMutableList())
}
preOrder(root.left)
preOrder(root.right)
@@ -37,13 +37,13 @@ fun main() {
printTree(root)
// 前序遍历
path = ArrayList()
res = ArrayList()
path = mutableListOf()
res = mutableListOf()
preOrder(root)
println("\n输出所有根节点到节点 7 的路径,路径中不包含值为 3 的节点")
for (path in res as ArrayList<List<TreeNode>>) {
val values: MutableList<Int> = ArrayList()
for (path in res!!) {
val values = mutableListOf<Int>()
for (node in path) {
values.add(node.value)
}