Hello 算法 1.2.0 繁体中文 Swift 版
+ 1, … , ? − 1 : // === File: iteration.swift === /* for 迴圈 */ func forLoop(n: Int) -> Int { var res = 0 // 迴圈求和 1, 2, ..., n-1, n for i in 1 ... n { res += i } return res } 第 2 章 複雜度分析 www ⋯ + ? : // === File: iteration.swift === /* while 迴圈 */ func whileLoop(n: Int) -> Int { var res = 0 var i = 1 // 初始化條件變數 // 迴圈求和 1, 2, ..., n-1, n while i <= n { res += i i += 1 // 更新條件變數 } // === File: iteration.swift === /* while 迴圈(兩次更新) */ func whileLoopII(n: Int) -> Int { var res = 0 var i = 1 // 初始化條件變數 // 迴圈求和 1, 4, 10, ... while i <= n { res += i // 更新條件變數 i += 1 i *= 20 码力 | 379 页 | 18.79 MB | 9 月前3Hello 算法 1.2.0 繁体中文 Kotlin 版
為 ?, ? + 1, … , ? − 1 : // === File: iteration.kt === /* for 迴圈 */ fun forLoop(n: Int): Int { var res = 0 // 迴圈求和 1, 2, ..., n-1, n for (i in 1..n) { res += i } return res } 第 2 章 複雜度分析 www + 2 + ⋯ + ? : // === File: iteration.kt === /* while 迴圈 */ fun whileLoop(n: Int): Int { var res = 0 var i = 1 // 初始化條件變數 // 迴圈求和 1, 2, ..., n-1, n while (i <= n) { res += i i++ // 更新條件變數 } return 迴圈實現: // === File: iteration.kt === /* while 迴圈(兩次更新) */ fun whileLoopII(n: Int): Int { var res = 0 var i = 1 // 初始化條件變數 // 迴圈求和 1, 4, 10, ... while (i <= n) { res += i // 更新條件變數 i++ i *= 20 码力 | 382 页 | 18.79 MB | 9 月前3Julia 1.11.4
is written: julia> struct MyUndefVarError <: Exception var::Symbol end julia> Base.showerror(io::IO, e::MyUndefVarError) = print(io, e.var, " not defined") Note When writing an error message, it new variable bindings each time they run. The variable need not be immediately assigned: julia> var1 = let x for i in 1:5 (i == 4) && (x = i; break) end x end 4 Whereas assignments might reassign distinct, but not guaranteed to be printed the same way across sessions. julia> typeof(x -> x + 1) var"#9#10" Types of closures are not necessarily singletons.CHAPTER 12. TYPES 149 julia> addy(y) = x0 码力 | 2007 页 | 6.73 MB | 3 月前3Julia 1.11.5 Documentation
is written: julia> struct MyUndefVarError <: Exception var::Symbol end julia> Base.showerror(io::IO, e::MyUndefVarError) = print(io, e.var, " not defined") Note When writing an error message, it new variable bindings each time they run. The variable need not be immediately assigned: julia> var1 = let x for i in 1:5 (i == 4) && (x = i; break) end x end 4 Whereas assignments might reassign distinct, but not guaranteed to be printed the same way across sessions. julia> typeof(x -> x + 1) var"#9#10" Types of closures are not necessarily singletons.CHAPTER 12. TYPES 149 julia> addy(y) = x0 码力 | 2007 页 | 6.73 MB | 3 月前3Julia 1.11.6 Release Notes
is written: julia> struct MyUndefVarError <: Exception var::Symbol end julia> Base.showerror(io::IO, e::MyUndefVarError) = print(io, e.var, " not defined") Note When writing an error message, it new variable bindings each time they run. The variable need not be immediately assigned: julia> var1 = let x for i in 1:5 (i == 4) && (x = i; break) end x end 4 Whereas assignments might reassign distinct, but not guaranteed to be printed the same way across sessions. julia> typeof(x -> x + 1) var"#9#10" Types of closures are not necessarily singletons.CHAPTER 12. TYPES 149 julia> addy(y) = x0 码力 | 2007 页 | 6.73 MB | 3 月前3Hello 算法 1.2.0 繁体中文 Dart 版
time_complexity.dart === /* 常數階 */ int constant(int n) { int count = 0; int size = 100000; for (var i = 0; i < size; i++) { count++; } return count; } 2. 線性階 ?(?) 線性階的操作數量相對於輸入資料大小 ? 以線性級別增長。線性階通常出現在單層迴圈中: 以線性級別增長。線性階通常出現在單層迴圈中: // === File: time_complexity.dart === /* 線性階 */ int linear(int n) { int count = 0; for (var i = 0; i < n; i++) { count++; 第 2 章 複雜度分析 www.hello‑algo.com 34 } return count; } 走訪陣列和走訪鏈結串列等操作的時間複雜度均為 === /* 線性階(走訪陣列) */ int arrayTraversal(Listnums) { int count = 0; // 迴圈次數與陣列長度成正比 for (var _num in nums) { count++; } return count; } 值得注意的是,輸入資料大小 ? 需根據輸入資料的型別來具體確定。比如在第一個示例中,變數 ? 為輸入資 0 码力 | 378 页 | 18.77 MB | 9 月前3Julia 1.12.0 RC1
is written: julia> struct MyUndefVarError <: Exception var::Symbol end julia> Base.showerror(io::IO, e::MyUndefVarError) = print(io, e.var, " not defined") Note When writing an error message, it new variable bindings each time they run. The variable need not be immediately assigned: julia> var1 = let x for i in 1:5 (i == 4) && (x = i; break) end x end 4 Whereas assignments might reassign distinct, but not guaranteed to be printed the same way across sessions. julia> typeof(x -> x + 1) var"#9#10" Types of closures are not necessarily singletons.CHAPTER 12. TYPES 149 julia> addy(y) = x0 码力 | 2057 页 | 7.44 MB | 3 月前3Julia 1.12.0 Beta4
is written: julia> struct MyUndefVarError <: Exception var::Symbol end julia> Base.showerror(io::IO, e::MyUndefVarError) = print(io, e.var, " not defined") Note When writing an error message, it new variable bindings each time they run. The variable need not be immediately assigned: julia> var1 = let x for i in 1:5 (i == 4) && (x = i; break) end x end 4 Whereas assignments might reassign distinct, but not guaranteed to be printed the same way across sessions. julia> typeof(x -> x + 1) var"#9#10" Types of closures are not necessarily singletons.CHAPTER 12. TYPES 149 julia> addy(y) = x0 码力 | 2057 页 | 7.44 MB | 3 月前3Julia 1.12.0 Beta3
is written: julia> struct MyUndefVarError <: Exception var::Symbol end julia> Base.showerror(io::IO, e::MyUndefVarError) = print(io, e.var, " not defined") Note When writing an error message, it new variable bindings each time they run. The variable need not be immediately assigned: julia> var1 = let x for i in 1:5 (i == 4) && (x = i; break) end x end 4 Whereas assignments might reassign distinct, but not guaranteed to be printed the same way across sessions. julia> typeof(x -> x + 1) var"#9#10" Types of closures are not necessarily singletons.CHAPTER 12. TYPES 149 julia> addy(y) = x0 码力 | 2057 页 | 7.44 MB | 3 月前3julia 1.12.0 beta1
is written: julia> struct MyUndefVarError <: Exception var::Symbol end julia> Base.showerror(io::IO, e::MyUndefVarError) = print(io, e.var, " not defined") Note When writing an error message, it new variable bindings each time they run. The variable need not be immediately assigned: julia> var1 = let x for i in 1:5 (i == 4) && (x = i; break) end x end 4 Whereas assignments might reassign distinct, but not guaranteed to be printed the same way across sessions. julia> typeof(x -> x + 1) var"#9#10" Types of closures are not necessarily singletons.CHAPTER 12. TYPES 149 julia> addy(y) = x0 码力 | 2047 页 | 7.41 MB | 3 月前3
共 30 条
- 1
- 2
- 3