Improve the consistency between code and comments in Kotlin (#1268)

* style(kotlin): Make code and comments consistent.

* style(kotlin): convert comment location.

* style(c): Add missing comment.

* style(kotlin): Remove redundant semicolon, parenthesis and brace

* style(kotlin): Put constants inside the function.

* style(kotlin): fix unnecessary indentation.

* style(swift): Add missing comment.

* style(kotlin): Add missing comment.

* style(kotlin): Remove redundant comment.

* style(kotlin): Add missing comment.

* Update linked_list.kt

* style(csharp,js,ts): Add missing comment.

* style(kotlin): Remove empty lines.

* Update list.cs

* Update list.js

* Update list.ts

* roll back to commit 1

* style(cs,js,ts): Add missing comment in docfile.

* style(kotlin): Use normal element swapping instead of scope functions.
This commit is contained in:
curtishd
2024-04-13 20:09:39 +08:00
committed by GitHub
parent b0d6fa0f38
commit 4d9bbe72e1
25 changed files with 74 additions and 61 deletions

View File

@@ -59,11 +59,7 @@ fun knapsackDFSMem(
}
/* 0-1 背包:动态规划 */
fun knapsackDP(
wgt: IntArray,
_val: IntArray,
cap: Int
): Int {
fun knapsackDP(wgt: IntArray, _val: IntArray, cap: Int): Int {
val n = wgt.size
// 初始化 dp 表
val dp = Array(n + 1) { IntArray(cap + 1) }
@@ -83,11 +79,7 @@ fun knapsackDP(
}
/* 0-1 背包:空间优化后的动态规划 */
fun knapsackDPComp(
wgt: IntArray,
_val: IntArray,
cap: Int
): Int {
fun knapsackDPComp(wgt: IntArray, _val: IntArray, cap: Int): Int {
val n = wgt.size
// 初始化 dp 表
val dp = IntArray(cap + 1)
@@ -97,8 +89,7 @@ fun knapsackDPComp(
for (c in cap downTo 1) {
if (wgt[i - 1] <= c) {
// 不选和选物品 i 这两种方案的较大值
dp[c] =
max(dp[c], dp[c - wgt[i - 1]] + _val[i - 1])
dp[c] = max(dp[c], dp[c - wgt[i - 1]] + _val[i - 1])
}
}
}