waterfall.zhang
BAN USERclass Program
{
public class Node
{
public int value;
public Node left, right;
public Node(int v, Node l, Node r)
{
this.value = v;
this.left = l;
this.right = r;
}
}
public static bool hasSum(int sum, Node root)
{
if (root == null)
{
if (sum == 0)
return true;
else
return false;
}
return hasSum(sum  root.value, root.left)  hasSum(sum  root.value, root.right);
}
}
use tree structure to capture the links:
for example,
root >companyA.com>page1.html (count)
>page2.html (count)
>companyB.com>page3.html (count)
.....
Tree grows as new links are found. If a link exists in the tree, count on the leaf is increased.
At the end, the path from the root to the leaf with the max count is the page which has the most incoming links.
Serialize: covert the tree into two array: one uses the preorder traversal and the other uses inorder traversal.
Deserialize: rebuild the tree from these two arrays.
public class PalindromeDate {
public static void main(String[] args) {
printDates(1000, 3010);
}
public static void printDates(int start, int end) {
int[] daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
for (int year = start; year <= end; year++) {
String yyyy = Integer.toString(year);
String mm = Integer.toString(year%10)+Integer.toString((year/10)%10);
String dd = Integer.toString((year/100)%10)+Integer.toString((year/1000)%10);
int m = Integer.parseInt(mm);
int d = Integer.parseInt(dd);
if (m > 0 && m < 13) {
if (d > 0 && d <= ((m1 != 2)? daysInMonth[m1]: (year%4 != 0)?28:29)) {
System.out.println(mm+dd+yyyy);
}
}
}
}
}

waterfall.zhang
August 10, 2010 use bit shift
int mod(int N)
{
return N((N>>4)<<4);
}
The value (in term of binary) of z is the same regardless signed or unsigned. If print z as signed int, you get 14, if you print z as unsigned int, you get the huge number, i.e. near 4G.
 waterfall.zhang August 08, 2010
it really depends on how the equals() is implemented. as the implementation above, then s1.equals(s2) is true.
if it is implemented as follow:
in this case s1.equals(s2) is false.
 waterfall.zhang January 27, 2011