 Hello 算法 1.2.0 繁体中文 Go 版Hello 演算法 Go 語言版 作者:靳宇棟(@krahets) 程式碼審閱:劉代富(@Reanon) Release 1.2.0 2024‑12‑06 序 兩年前,我在力扣上分享了“劍指 Offer”系列題解,受到了許多讀者的鼓勵與支持。在與讀者交流期間,我 最常被問到的一個問題是“如何入門演算法”。漸漸地,我對這個問題產生了濃厚的興趣。 兩眼一抹黑地刷題似乎是最受歡迎的方法,簡 記錄。需要注意的是,Python 中 range(a, b) 對應的區間是“左閉右開”的,對應的走訪範圍為 ?, ? + 1, … , ? − 1 : // === File: iteration.go === /* for 迴圈 */ func forLoop(n int) int { res := 0 // 迴圈求和 1, 2, ..., n-1, n for i := 1; i <= 迴圈中,程式每輪都會先檢查條件,如果條 件為真,則繼續執行,否則就結束迴圈。 下面我們用 while 迴圈來實現求和 1 + 2 + ⋯ + ? : // === File: iteration.go === /* while 迴圈 */ func whileLoop(n int) int { res := 0 // 初始化條件變數 i := 1 // 迴圈求和 1, 2, ...,0 码力 | 385 页 | 18.80 MB | 10 月前3 Hello 算法 1.2.0 繁体中文 Go 版Hello 演算法 Go 語言版 作者:靳宇棟(@krahets) 程式碼審閱:劉代富(@Reanon) Release 1.2.0 2024‑12‑06 序 兩年前,我在力扣上分享了“劍指 Offer”系列題解,受到了許多讀者的鼓勵與支持。在與讀者交流期間,我 最常被問到的一個問題是“如何入門演算法”。漸漸地,我對這個問題產生了濃厚的興趣。 兩眼一抹黑地刷題似乎是最受歡迎的方法,簡 記錄。需要注意的是,Python 中 range(a, b) 對應的區間是“左閉右開”的,對應的走訪範圍為 ?, ? + 1, … , ? − 1 : // === File: iteration.go === /* for 迴圈 */ func forLoop(n int) int { res := 0 // 迴圈求和 1, 2, ..., n-1, n for i := 1; i <= 迴圈中,程式每輪都會先檢查條件,如果條 件為真,則繼續執行,否則就結束迴圈。 下面我們用 while 迴圈來實現求和 1 + 2 + ⋯ + ? : // === File: iteration.go === /* while 迴圈 */ func whileLoop(n int) int { res := 0 // 初始化條件變數 i := 1 // 迴圈求和 1, 2, ...,0 码力 | 385 页 | 18.80 MB | 10 月前3
 Julia 1.12.0 RC1a tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however:CHAPTER 9. FUNCTIONS 85 julia> x = (2, 3, 4) (2, 3, 4) julia> function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 2057 页 | 7.44 MB | 3 月前3 Julia 1.12.0 RC1a tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however:CHAPTER 9. FUNCTIONS 85 julia> x = (2, 3, 4) (2, 3, 4) julia> function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 2057 页 | 7.44 MB | 3 月前3
 Julia 1.12.0 Beta4a tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however:CHAPTER 9. FUNCTIONS 85 julia> x = (2, 3, 4) (2, 3, 4) julia> function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 2057 页 | 7.44 MB | 3 月前3 Julia 1.12.0 Beta4a tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however:CHAPTER 9. FUNCTIONS 85 julia> x = (2, 3, 4) (2, 3, 4) julia> function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 2057 页 | 7.44 MB | 3 月前3
 Julia 1.12.0 Beta3a tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however:CHAPTER 9. FUNCTIONS 85 julia> x = (2, 3, 4) (2, 3, 4) julia> function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 2057 页 | 7.44 MB | 3 月前3 Julia 1.12.0 Beta3a tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however:CHAPTER 9. FUNCTIONS 85 julia> x = (2, 3, 4) (2, 3, 4) julia> function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 2057 页 | 7.44 MB | 3 月前3
 julia 1.12.0 beta1a tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however:CHAPTER 9. FUNCTIONS 85 julia> x = (2, 3, 4) (2, 3, 4) julia> function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 2047 页 | 7.41 MB | 3 月前3 julia 1.12.0 beta1a tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however:CHAPTER 9. FUNCTIONS 85 julia> x = (2, 3, 4) (2, 3, 4) julia> function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 2047 页 | 7.41 MB | 3 月前3
 julia 1.13.0 DEVa tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however:CHAPTER 9. FUNCTIONS 85 julia> x = (2, 3, 4) (2, 3, 4) julia> function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 2058 页 | 7.45 MB | 3 月前3 julia 1.13.0 DEVa tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however:CHAPTER 9. FUNCTIONS 85 julia> x = (2, 3, 4) (2, 3, 4) julia> function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 2058 页 | 7.45 MB | 3 月前3
 julia 1.10.10a tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however: julia> x = (2, 3, 4) (2, 3, 4) julia> bar(1,x...) (1, 2, (3 function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 1692 页 | 6.34 MB | 3 月前3 julia 1.10.10a tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however: julia> x = (2, 3, 4) (2, 3, 4) julia> bar(1,x...) (1, 2, (3 function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 1692 页 | 6.34 MB | 3 月前3
 Julia 1.10.9a tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however: julia> x = (2, 3, 4) (2, 3, 4) julia> bar(1,x...) (1, 2, (3 function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 1692 页 | 6.34 MB | 3 月前3 Julia 1.10.9a tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however: julia> x = (2, 3, 4) (2, 3, 4) julia> bar(1,x...) (1, 2, (3 function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 1692 页 | 6.34 MB | 3 月前3
 Julia 1.11.4a tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however:CHAPTER 9. FUNCTIONS 85 julia> x = (2, 3, 4) (2, 3, 4) julia> function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 2007 页 | 6.73 MB | 3 月前3 Julia 1.11.4a tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however:CHAPTER 9. FUNCTIONS 85 julia> x = (2, 3, 4) (2, 3, 4) julia> function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 2007 页 | 6.73 MB | 3 月前3
 Julia 1.11.5 Documentationa tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however:CHAPTER 9. FUNCTIONS 85 julia> x = (2, 3, 4) (2, 3, 4) julia> function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 2007 页 | 6.73 MB | 3 月前3 Julia 1.11.5 Documentationa tuple of values is spliced into a varargs call precisely where the variable number of arguments go. This need not be the case, however:CHAPTER 9. FUNCTIONS 85 julia> x = (2, 3, 4) (2, 3, 4) julia> function body into the REPL to debug it—you have to add global annotations and then remove them again to go back; 2. Beginners will write this kind of code without the global and have no idea why their code myfilter(Apadded, kernel, NoPad()) # indicate the new boundary conditions end # other padding methods go here function myfilter(A, kernel, ::NoPad) # Here's the "real" implementation of the core computation0 码力 | 2007 页 | 6.73 MB | 3 月前3
共 34 条
- 1
- 2
- 3
- 4













