feat(Kotlin): Replace value with _val (#1254)

* ci(kotlin): Add workflow file.

* Update kotlin.yml

* style(kotlin): value -> _val

---------

Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
curtishd
2024-04-10 18:09:43 +08:00
committed by GitHub
parent 39e2e1a5c1
commit 1623e3c6a8
28 changed files with 152 additions and 152 deletions
@@ -16,7 +16,7 @@ fun preOrder(root: TreeNode?) {
if (root == null) {
return
}
if (root.value == 7) {
if (root._val == 7) {
// 记录解
res!!.add(root)
}
@@ -37,7 +37,7 @@ fun main() {
println("\n输出所有值为 7 的节点")
val vals = mutableListOf<Int>()
for (node in res!!) {
vals.add(node.value)
vals.add(node._val)
}
println(vals)
}
@@ -19,7 +19,7 @@ fun preOrder(root: TreeNode?) {
}
// 尝试
path!!.add(root)
if (root.value == 7) {
if (root._val == 7) {
// 记录解
res!!.add(path!!.toMutableList())
}
@@ -42,10 +42,10 @@ fun main() {
println("\n输出所有根节点到节点 7 的路径")
for (path in res!!) {
val values = mutableListOf<Int>()
val _vals = mutableListOf<Int>()
for (node in path) {
values.add(node.value)
_vals.add(node._val)
}
println(values)
println(_vals)
}
}
@@ -15,12 +15,12 @@ var res: MutableList<MutableList<TreeNode>>? = null
/* 前序遍历:例题三 */
fun preOrder(root: TreeNode?) {
// 剪枝
if (root == null || root.value == 3) {
if (root == null || root._val == 3) {
return
}
// 尝试
path!!.add(root)
if (root.value == 7) {
if (root._val == 7) {
// 记录解
res!!.add(path!!.toMutableList())
}
@@ -43,10 +43,10 @@ fun main() {
println("\n输出所有根节点到节点 7 的路径,路径中不包含值为 3 的节点")
for (path in res!!) {
val values = mutableListOf<Int>()
val _vals = mutableListOf<Int>()
for (node in path) {
values.add(node.value)
_vals.add(node._val)
}
println(values)
println(_vals)
}
}
@@ -11,7 +11,7 @@ import utils.printTree
/* 判断当前状态是否为解 */
fun isSolution(state: MutableList<TreeNode?>): Boolean {
return state.isNotEmpty() && state[state.size - 1]?.value == 7
return state.isNotEmpty() && state[state.size - 1]?._val == 7
}
/* 记录解 */
@@ -21,7 +21,7 @@ fun recordSolution(state: MutableList<TreeNode?>?, res: MutableList<MutableList<
/* 判断在当前状态下,该选择是否合法 */
fun isValid(state: MutableList<TreeNode?>?, choice: TreeNode?): Boolean {
return choice != null && choice.value != 3
return choice != null && choice._val != 3
}
/* 更新状态 */
@@ -74,7 +74,7 @@ fun main() {
val vals = mutableListOf<Int>()
for (node in path!!) {
if (node != null) {
vals.add(node.value)
vals.add(node._val)
}
}
println(vals)