LeetCode
LeetCode copied to clipboard
杂记
如何取数组的中间值? Method 1
middle = (left + right) / 2;
- 局限:(left + right) 可能会出现溢出,从而造成错误
Method 2
middle = left + (right - left)/2;
- 避免了溢出的情况
Method 3
middle = left + (right - left)>>1;
- 利用位运算,速度更快
Reference
Iterative(迭代) vs recursive(递归)
recursive(递归): 是指直接or间接调用自身的函数。它主要用于当一个更大问题的解决方案可以用更小的问题来表达时。 iterative(迭代): 是重复执行一组命令,直到循环的条件变为“假”。它包括初始化、比较、在迭代中执行语句以及更新控制变量。
Reference
- 递归(recursion) 迭代(iteration)的区别
- https://csruiliu.github.io/blog/20160616-iteration-recursion/
- https://bbotte.github.io/python_project/python-iterative-and-recursive.html
- https://www.jianshu.com/p/32bcc45efd32
Online Java Compiler
Can use the following online compiler to verify some easy things
- https://www.tutorialspoint.com/compile_java_online.php
/* Online Java Compiler and Editor */
public class HelloWorld{
public static void main(String []args){
System.out.println("Hello, World!");
// Dividend
int a = -123;
// Divisor
int b = 10;
// Mod
int k = a % b;
System.out.println(k);
System.out.println(Integer.MAX_VALUE);
System.out.println(Integer.MIN_VALUE);
}
}
关于LinkedList的长度问题
- https://github.com/ylqi007/LeetCode/blob/master/problems/0019.Remove_Nth_Node_From_End_of_List.md#appendix