mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-11-04 14:18:20 +08:00 
			
		
		
		
	fix: Some Ruby code (#1231)
* fix: ruby code block - chapter computational complexity * fix: ruby code - chapter array and linkedlist
This commit is contained in:
		@ -45,8 +45,8 @@ end
 | 
				
			|||||||
### 删除索引 index 处的元素 ###
 | 
					### 删除索引 index 处的元素 ###
 | 
				
			||||||
def remove(nums, index)
 | 
					def remove(nums, index)
 | 
				
			||||||
  # 把索引 index 之后的所有元素向前移动一位
 | 
					  # 把索引 index 之后的所有元素向前移动一位
 | 
				
			||||||
  for i in index...nums.length
 | 
					  for i in index...(nums.length - 1)
 | 
				
			||||||
    nums[i] = nums[i + 1] || 0
 | 
					    nums[i] = nums[i + 1]
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -191,11 +191,11 @@
 | 
				
			|||||||
    ```ruby title=""
 | 
					    ```ruby title=""
 | 
				
			||||||
    # 在某运行平台下
 | 
					    # 在某运行平台下
 | 
				
			||||||
    def algorithm(n)
 | 
					    def algorithm(n)
 | 
				
			||||||
        a = 2       # 1 ns 
 | 
					        a = 2       # 1 ns
 | 
				
			||||||
        a = a + 1   # 1 ns
 | 
					        a = a + 1   # 1 ns
 | 
				
			||||||
        a = a * 2   # 10 ns
 | 
					        a = a * 2   # 10 ns
 | 
				
			||||||
        # 循环 n 次
 | 
					        # 循环 n 次
 | 
				
			||||||
        (n...0).each do # 1 ns
 | 
					        (0...n).each do # 1 ns
 | 
				
			||||||
            puts 0      # 5 ns
 | 
					            puts 0      # 5 ns
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
@ -516,7 +516,7 @@ $$
 | 
				
			|||||||
    // 算法 C 的时间复杂度:常数阶
 | 
					    // 算法 C 的时间复杂度:常数阶
 | 
				
			||||||
    fn algorithm_C(n: i32) void {
 | 
					    fn algorithm_C(n: i32) void {
 | 
				
			||||||
        _ = n;
 | 
					        _ = n;
 | 
				
			||||||
        for (0..1000000) |_| { 
 | 
					        for (0..1000000) |_| {
 | 
				
			||||||
            std.debug.print("{}\n", .{0});
 | 
					            std.debug.print("{}\n", .{0});
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -690,7 +690,7 @@ $$
 | 
				
			|||||||
        for (int i = 0; i < n; i++) {   // +1(每轮都执行 i ++)
 | 
					        for (int i = 0; i < n; i++) {   // +1(每轮都执行 i ++)
 | 
				
			||||||
            printf("%d", 0);            // +1
 | 
					            printf("%d", 0);            // +1
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }  
 | 
					    }
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "Kotlin"
 | 
					=== "Kotlin"
 | 
				
			||||||
@ -1021,13 +1021,13 @@ $T(n)$ 是一次函数,说明其运行时间的增长趋势是线性的,因
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // +n(技巧 2)
 | 
					        // +n(技巧 2)
 | 
				
			||||||
        for(0..(5 * n + 1)) |_| {
 | 
					        for(0..(5 * n + 1)) |_| {
 | 
				
			||||||
            std.debug.print("{}\n", .{0}); 
 | 
					            std.debug.print("{}\n", .{0});
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // +n*n(技巧 3)
 | 
					        // +n*n(技巧 3)
 | 
				
			||||||
        for(0..(2 * n)) |_| {
 | 
					        for(0..(2 * n)) |_| {
 | 
				
			||||||
            for(0..(n + 1)) |_| {
 | 
					            for(0..(n + 1)) |_| {
 | 
				
			||||||
                std.debug.print("{}\n", .{0}); 
 | 
					                std.debug.print("{}\n", .{0});
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user