 Hello 算法 1.2.0 繁体中文 Kotlin 版Hello 演算法 Kotlin 語言版 作者:靳宇棟(@krahets) 程式碼審閱:陳東輝(@curtishd) Release 1.2.0 2024‑12‑06 序 兩年前,我在力扣上分享了“劍指 Offer”系列題解,受到了許多讀者的鼓勵與支持。在與讀者交流期間,我 最常被問到的一個問題是“如何入門演算法”。漸漸地,我對這個問題產生了濃厚的興趣。 兩眼一抹黑地刷題似乎是最受歡 maxHeap.add(_val) // 從底至頂堆積化 siftUp(size() - 1) } /* 從節點 i 開始,從底至頂堆積化 */ fun siftUp(it: Int) { // Kotlin 的函式參數不可變,因此建立臨時變數 var i = it while (true) { // 獲取節點 i 的父節點 val p = parent(i) // 當“越過根節點”或“節點無須修復”時,結束堆積化 從頂至底堆積化 siftDown(0) // 返回堆積頂元素 return _val } /* 從節點 i 開始,從頂至底堆積化 */ fun siftDown(it: Int) { // Kotlin 的函式參數不可變,因此建立臨時變數 var i = it while (true) { // 判斷節點 i, l, r 中值最大的節點,記為 ma val l = left(i) val0 码力 | 382 页 | 18.79 MB | 10 月前3 Hello 算法 1.2.0 繁体中文 Kotlin 版Hello 演算法 Kotlin 語言版 作者:靳宇棟(@krahets) 程式碼審閱:陳東輝(@curtishd) Release 1.2.0 2024‑12‑06 序 兩年前,我在力扣上分享了“劍指 Offer”系列題解,受到了許多讀者的鼓勵與支持。在與讀者交流期間,我 最常被問到的一個問題是“如何入門演算法”。漸漸地,我對這個問題產生了濃厚的興趣。 兩眼一抹黑地刷題似乎是最受歡 maxHeap.add(_val) // 從底至頂堆積化 siftUp(size() - 1) } /* 從節點 i 開始,從底至頂堆積化 */ fun siftUp(it: Int) { // Kotlin 的函式參數不可變,因此建立臨時變數 var i = it while (true) { // 獲取節點 i 的父節點 val p = parent(i) // 當“越過根節點”或“節點無須修復”時,結束堆積化 從頂至底堆積化 siftDown(0) // 返回堆積頂元素 return _val } /* 從節點 i 開始,從頂至底堆積化 */ fun siftDown(it: Int) { // Kotlin 的函式參數不可變,因此建立臨時變數 var i = it while (true) { // 判斷節點 i, l, r 中值最大的節點,記為 ma val l = left(i) val0 码力 | 382 页 | 18.79 MB | 10 月前3
 Hello 算法 1.2.0 繁体中文 JavaScript 版記錄。需要注意的是,Python 中 range(a, b) 對應的區間是“左閉右開”的,對應的走訪範圍為 ?, ? + 1, … , ? − 1 : // === File: iteration.js === /* for 迴圈 */ function forLoop(n) { let res = 0; // 迴圈求和 1, 2, ..., n-1, n for (let i = 1; 迴圈中,程式每輪都會先檢查條件,如果條 件為真,則繼續執行,否則就結束迴圈。 下面我們用 while 迴圈來實現求和 1 + 2 + ⋯ + ? : // === File: iteration.js === /* while 迴圈 */ function whileLoop(n) { let res = 0; let i = 1; // 初始化條件變數 // 迴圈求和 1, 2, . 複雜度分析 www.hello‑algo.com 21 例如在以下程式碼中,條件變數 ? 每輪進行兩次更新,這種情況就不太方便用 for 迴圈實現: // === File: iteration.js === /* while 迴圈(兩次更新) */ function whileLoopII(n) { let res = 0; let i = 1; // 初始化條件變數 // 迴圈求和0 码力 | 379 页 | 18.78 MB | 10 月前3 Hello 算法 1.2.0 繁体中文 JavaScript 版記錄。需要注意的是,Python 中 range(a, b) 對應的區間是“左閉右開”的,對應的走訪範圍為 ?, ? + 1, … , ? − 1 : // === File: iteration.js === /* for 迴圈 */ function forLoop(n) { let res = 0; // 迴圈求和 1, 2, ..., n-1, n for (let i = 1; 迴圈中,程式每輪都會先檢查條件,如果條 件為真,則繼續執行,否則就結束迴圈。 下面我們用 while 迴圈來實現求和 1 + 2 + ⋯ + ? : // === File: iteration.js === /* while 迴圈 */ function whileLoop(n) { let res = 0; let i = 1; // 初始化條件變數 // 迴圈求和 1, 2, . 複雜度分析 www.hello‑algo.com 21 例如在以下程式碼中,條件變數 ? 每輪進行兩次更新,這種情況就不太方便用 for 迴圈實現: // === File: iteration.js === /* while 迴圈(兩次更新) */ function whileLoopII(n) { let res = 0; let i = 1; // 初始化條件變數 // 迴圈求和0 码力 | 379 页 | 18.78 MB | 10 月前3
 快快樂樂學會 Angular 2 網站開發框架webpack 自動合併 ) – 支援延遲載入機制與伺服器渲染機制 (Node.js & ASP.NET ) • 學習曲線更低 – 採用 TypeScript 語法更簡潔 ( 類別、介面、屬性、方法 ) – 移除超過 40+ 個 directives • 平台支援更強大 – 支援 Browser, Node.js, NativeScript, React Native, … 11 Angular0 码力 | 38 页 | 1.12 MB | 1 年前3 快快樂樂學會 Angular 2 網站開發框架webpack 自動合併 ) – 支援延遲載入機制與伺服器渲染機制 (Node.js & ASP.NET ) • 學習曲線更低 – 採用 TypeScript 語法更簡潔 ( 類別、介面、屬性、方法 ) – 移除超過 40+ 個 directives • 平台支援更強大 – 支援 Browser, Node.js, NativeScript, React Native, … 11 Angular0 码力 | 38 页 | 1.12 MB | 1 年前3
 julia 1.10.10An alternative for analyzing Chromium heap snapshots is with the VS Code extension ms-vscode.vscode-js-profile-flame. The Firefox heap snapshots are of a different format, and Firefox currently may not ExamplesCHAPTER 93. SPARSEARRAYS API 1467 julia> Is = [1; 2; 3]; julia> Js = [1; 2; 3]; julia> Vs = [1; 2; 3]; julia> sparse(Is, Js, Vs) 3×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries: 1 ⋅ ⋅ Smith. git fetch origin git checkout release-x.y git rebase origin/release-x.y git checkout -b js/backport-x.y This ensures that your local copy of release-x.y is up to date with origin before you0 码力 | 1692 页 | 6.34 MB | 3 月前3 julia 1.10.10An alternative for analyzing Chromium heap snapshots is with the VS Code extension ms-vscode.vscode-js-profile-flame. The Firefox heap snapshots are of a different format, and Firefox currently may not ExamplesCHAPTER 93. SPARSEARRAYS API 1467 julia> Is = [1; 2; 3]; julia> Js = [1; 2; 3]; julia> Vs = [1; 2; 3]; julia> sparse(Is, Js, Vs) 3×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries: 1 ⋅ ⋅ Smith. git fetch origin git checkout release-x.y git rebase origin/release-x.y git checkout -b js/backport-x.y This ensures that your local copy of release-x.y is up to date with origin before you0 码力 | 1692 页 | 6.34 MB | 3 月前3
 Julia 1.10.9An alternative for analyzing Chromium heap snapshots is with the VS Code extension ms-vscode.vscode-js-profile-flame. The Firefox heap snapshots are of a different format, and Firefox currently may not ExamplesCHAPTER 93. SPARSEARRAYS API 1467 julia> Is = [1; 2; 3]; julia> Js = [1; 2; 3]; julia> Vs = [1; 2; 3]; julia> sparse(Is, Js, Vs) 3×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries: 1 ⋅ ⋅ Smith. git fetch origin git checkout release-x.y git rebase origin/release-x.y git checkout -b js/backport-x.y This ensures that your local copy of release-x.y is up to date with origin before you0 码力 | 1692 页 | 6.34 MB | 3 月前3 Julia 1.10.9An alternative for analyzing Chromium heap snapshots is with the VS Code extension ms-vscode.vscode-js-profile-flame. The Firefox heap snapshots are of a different format, and Firefox currently may not ExamplesCHAPTER 93. SPARSEARRAYS API 1467 julia> Is = [1; 2; 3]; julia> Js = [1; 2; 3]; julia> Vs = [1; 2; 3]; julia> sparse(Is, Js, Vs) 3×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries: 1 ⋅ ⋅ Smith. git fetch origin git checkout release-x.y git rebase origin/release-x.y git checkout -b js/backport-x.y This ensures that your local copy of release-x.y is up to date with origin before you0 码力 | 1692 页 | 6.34 MB | 3 月前3
 Julia 1.11.4An alternative for analyzing Chromium heap snapshots is with the VS Code extension ms-vscode.vscode-js-profile-flame. The Firefox heap snapshots are of a different format, and Firefox currently may not see SparseArrays.sparse!. Examples julia> Is = [1; 2; 3]; julia> Js = [1; 2; 3]; julia> Vs = [1; 2; 3]; julia> sparse(Is, Js, Vs) 3×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries: 1 ⋅ ⋅ Smith. git fetch origin git checkout release-x.y git rebase origin/release-x.y git checkout -b js/backport-x.y This ensures that your local copy of release-x.y is up to date with origin before you0 码力 | 2007 页 | 6.73 MB | 3 月前3 Julia 1.11.4An alternative for analyzing Chromium heap snapshots is with the VS Code extension ms-vscode.vscode-js-profile-flame. The Firefox heap snapshots are of a different format, and Firefox currently may not see SparseArrays.sparse!. Examples julia> Is = [1; 2; 3]; julia> Js = [1; 2; 3]; julia> Vs = [1; 2; 3]; julia> sparse(Is, Js, Vs) 3×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries: 1 ⋅ ⋅ Smith. git fetch origin git checkout release-x.y git rebase origin/release-x.y git checkout -b js/backport-x.y This ensures that your local copy of release-x.y is up to date with origin before you0 码力 | 2007 页 | 6.73 MB | 3 月前3
 Julia 1.11.5 DocumentationAn alternative for analyzing Chromium heap snapshots is with the VS Code extension ms-vscode.vscode-js-profile-flame. The Firefox heap snapshots are of a different format, and Firefox currently may not see SparseArrays.sparse!. Examples julia> Is = [1; 2; 3]; julia> Js = [1; 2; 3]; julia> Vs = [1; 2; 3]; julia> sparse(Is, Js, Vs) 3×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries: 1 ⋅ ⋅ Smith. git fetch origin git checkout release-x.y git rebase origin/release-x.y git checkout -b js/backport-x.y This ensures that your local copy of release-x.y is up to date with origin before you0 码力 | 2007 页 | 6.73 MB | 3 月前3 Julia 1.11.5 DocumentationAn alternative for analyzing Chromium heap snapshots is with the VS Code extension ms-vscode.vscode-js-profile-flame. The Firefox heap snapshots are of a different format, and Firefox currently may not see SparseArrays.sparse!. Examples julia> Is = [1; 2; 3]; julia> Js = [1; 2; 3]; julia> Vs = [1; 2; 3]; julia> sparse(Is, Js, Vs) 3×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries: 1 ⋅ ⋅ Smith. git fetch origin git checkout release-x.y git rebase origin/release-x.y git checkout -b js/backport-x.y This ensures that your local copy of release-x.y is up to date with origin before you0 码力 | 2007 页 | 6.73 MB | 3 月前3
 Julia 1.11.6 Release NotesAn alternative for analyzing Chromium heap snapshots is with the VS Code extension ms-vscode.vscode-js-profile-flame. The Firefox heap snapshots are of a different format, and Firefox currently may not see SparseArrays.sparse!. Examples julia> Is = [1; 2; 3]; julia> Js = [1; 2; 3]; julia> Vs = [1; 2; 3]; julia> sparse(Is, Js, Vs) 3×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries: 1 ⋅ ⋅ Smith. git fetch origin git checkout release-x.y git rebase origin/release-x.y git checkout -b js/backport-x.y This ensures that your local copy of release-x.y is up to date with origin before you0 码力 | 2007 页 | 6.73 MB | 3 月前3 Julia 1.11.6 Release NotesAn alternative for analyzing Chromium heap snapshots is with the VS Code extension ms-vscode.vscode-js-profile-flame. The Firefox heap snapshots are of a different format, and Firefox currently may not see SparseArrays.sparse!. Examples julia> Is = [1; 2; 3]; julia> Js = [1; 2; 3]; julia> Vs = [1; 2; 3]; julia> sparse(Is, Js, Vs) 3×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries: 1 ⋅ ⋅ Smith. git fetch origin git checkout release-x.y git rebase origin/release-x.y git checkout -b js/backport-x.y This ensures that your local copy of release-x.y is up to date with origin before you0 码力 | 2007 页 | 6.73 MB | 3 月前3
 julia 1.13.0 DEVAn alternative for analyzing Chromium heap snapshots is with the VS Code extension ms-vscode.vscode-js-profile-flame. The Firefox heap snapshots are of a different format, and Firefox currently may not see SparseArrays.sparse!. Examples julia> Is = [1; 2; 3]; julia> Js = [1; 2; 3]; julia> Vs = [1; 2; 3]; julia> sparse(Is, Js, Vs) 3×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries: 1 ⋅ ⋅ Smith. git fetch origin git checkout release-x.y git rebase origin/release-x.y git checkout -b js/backport-x.y This ensures that your local copy of release-x.y is up to date with origin before you0 码力 | 2058 页 | 7.45 MB | 3 月前3 julia 1.13.0 DEVAn alternative for analyzing Chromium heap snapshots is with the VS Code extension ms-vscode.vscode-js-profile-flame. The Firefox heap snapshots are of a different format, and Firefox currently may not see SparseArrays.sparse!. Examples julia> Is = [1; 2; 3]; julia> Js = [1; 2; 3]; julia> Vs = [1; 2; 3]; julia> sparse(Is, Js, Vs) 3×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries: 1 ⋅ ⋅ Smith. git fetch origin git checkout release-x.y git rebase origin/release-x.y git checkout -b js/backport-x.y This ensures that your local copy of release-x.y is up to date with origin before you0 码力 | 2058 页 | 7.45 MB | 3 月前3
 Julia 1.12.0 RC1An alternative for analyzing Chromium heap snapshots is with the VS Code extension ms-vscode.vscode-js-profile-flame. The Firefox heap snapshots are of a different format, and Firefox currently may not see SparseArrays.sparse!. Examples julia> Is = [1; 2; 3]; julia> Js = [1; 2; 3]; julia> Vs = [1; 2; 3]; julia> sparse(Is, Js, Vs) 3×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries: 1 ⋅ ⋅ Smith. git fetch origin git checkout release-x.y git rebase origin/release-x.y git checkout -b js/backport-x.y This ensures that your local copy of release-x.y is up to date with origin before you0 码力 | 2057 页 | 7.44 MB | 3 月前3 Julia 1.12.0 RC1An alternative for analyzing Chromium heap snapshots is with the VS Code extension ms-vscode.vscode-js-profile-flame. The Firefox heap snapshots are of a different format, and Firefox currently may not see SparseArrays.sparse!. Examples julia> Is = [1; 2; 3]; julia> Js = [1; 2; 3]; julia> Vs = [1; 2; 3]; julia> sparse(Is, Js, Vs) 3×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries: 1 ⋅ ⋅ Smith. git fetch origin git checkout release-x.y git rebase origin/release-x.y git checkout -b js/backport-x.y This ensures that your local copy of release-x.y is up to date with origin before you0 码力 | 2057 页 | 7.44 MB | 3 月前3
共 35 条
- 1
- 2
- 3
- 4













