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
@@ -8,9 +8,9 @@ package chapter_array_and_linkedlist
/* Driver Code */
fun main() {
/* 初始化列表 */
// 可变集合
val numbers = mutableListOf(1, 3, 2, 5, 4)
val nums = ArrayList<Int>(numbers)
val nums = mutableListOf(1, 3, 2, 5, 4)
println("列表 nums = $nums")
/* 访问元素 */
@@ -53,11 +53,11 @@ fun main() {
}
/* 拼接两个列表*/
val nums1 = ArrayList<Int>(listOf(6, 8, 7, 10, 9))
val nums1 = mutableListOf(6, 8, 7, 10, 9)
nums.addAll(nums1)
println("将列表 nums1 拼接到 nums 之后,得到 nums = $nums")
/* 排序列表 */
nums.sort() //排序后,列表元素从小到大排列
nums.sort()
println("排序列表后 nums = $nums")
}