tips
// if (digit%2==1) {str.append(1);}
else if (digit%2==0) {append(0);}
is the same as
str.append(digit%2);
// Math.max(); find the max value
// ?: can be used to reduce the size of if...else...
- // 向前比较和向后比较: 向前比较比较好,可以少加一个判断简化代码。
If you allocate a new array with arr = new Employee[100], the size of that array (arr.length) is going to be 100. It has 100 elements. All the elements are initially null (as this is an array of object references), but still, there are 100 elements.
If you do something like list = new ArrayList
(100), and try to check list.size(), you'll get 0. There are no elements in the list. if (i >= 0 && nums1[i] > nums2[j]) { // short circuiting nums1[pos--] = nums1[i--];
- Math.pow will return a double, not int
int start = (int) Math.pow(10, n-1);
- while (middle - 1 > 0) {
cur = cur.next; // 必杀!while loop里面的循环条件变化 middle--; }
好好审题, 想好初始化
循环条件需仔细判断
看到循环,一定提醒自己写终止条件
&& and ||
- a && b can't be true if a is false, so if a really is false, there's no need to examine b.
- a || b can't be false if a is true, so if a really is true, there's no need to examine b.
- They're called short-circuit operators for that reason.
- && looks for false, means if first argument false, it wont test second whether it is true or false.
- || looks for true, means even though first argument false, it test for second. If both are false then false otherwise true.
if true/false 同时出现,直接return条件
return stack.empty();
- 不要背答案,仔细思考操作位和循环条件。
- 如果不是final,不能用大写字母表示一个variable
- line 22: 'root' hides a field.
- queue.offer(root)
- Collections.reverse(list) return a null
- Stackoverflow error happens because the recursion is too deeply.