A bunch of tips - optimization of common writing (continuously updated..)

  1. Swap the values ​​of two numbers without defining a variable
int temp = a;
a = b;
b = temp;

can be replaced with:

a = a ^ b;
b = a ^ b;
a = a ^ b;

For details, see Tips – Use XOR to replace the original constant exchange

  1. Use >> to replace the original /2 to take the midpoint
    int mid = (left + right) / 2;
    int mid = left + ((right - left) >> 1); /

Guess you like

Origin blog.csdn.net/abaidaye/article/details/126600250