二叉搜索树的后序遍历序列
class Solution {public boolean verifyPostorder(int[] postorder) {return recur(postorder, 0, postorder.length-1);}public boolean recur(int[] postorder, int i, int j) {if (i >= j)return true;int p = i;while (postorder[p] < postorder[j])p++;int m = p;while (postorder[p] > postorder[j])p++;return p==j && recur(postorder, i, m-1) && recur(postorder, m, j-1);}}
求 1+2+…+n ,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。 ```java // 方法一:递归 方法二:短路计算 class Solution { public int sumNums(int n) {
boolean flag = n > 0 && (n += sumNums(n - 1)) > 0;return n;
}
} ```
4种引用
(1)强引用:在Java中最常见的就是强引用。在把一个对象赋给一个引用变量时,这个引用变量就是一个强引用。有强引用的对象一定为可达性状态,所以不会被垃圾回收机制回收。因此,强引用是造成Java内存泄漏(Memory Link)的主要原因。 (2)软引用:软引用通过SoftReference类实现。如果一个对象只有软引用,则在系统内存空间不足时该对象将被回收。 (3)弱引用:弱引用通过WeakReference类实现,如果一个对象只有弱引用,则在垃圾回收过程中一定会被回收。 (4)虚引用:虚引用通过PhantomReference类实现,虚引用和引用队列联合使用,主要用于跟踪对象的垃圾回收状态。
垃圾收集器

