LeetCode icon indicating copy to clipboard operation
LeetCode copied to clipboard

杂记

Open ylqi007 opened this issue 2 years ago • 4 comments

如何取数组的中间值? Method 1

middle = (left + right) / 2;
  • 局限:(left + right) 可能会出现溢出,从而造成错误

Method 2

middle = left + (right - left)/2;
  • 避免了溢出的情况

Method 3

middle = left + (right - left)>>1;
  • 利用位运算,速度更快

Reference

ylqi007 avatar Nov 02 '23 06:11 ylqi007

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

ylqi007 avatar Nov 03 '23 04:11 ylqi007

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);
     }
}

ylqi007 avatar Nov 06 '23 05:11 ylqi007

关于LinkedList的长度问题

  • https://github.com/ylqi007/LeetCode/blob/master/problems/0019.Remove_Nth_Node_From_End_of_List.md#appendix

ylqi007 avatar Nov 20 '23 01:11 ylqi007