摘要:import java.util.ArrayList;import java.util.LinkedList;import java.util.List;import java.util.Queue;import java.util.Stack;enum Dirction {left , right} public class Tree { private BinaryTreeNode root; private List list = new ArrayList(); Dirction current = Dirction.right; ...
阅读全文
摘要:Given a node from a cyclic linked list which has been sorted, write a function to insert a value into the list such that it remains a cyclic sorted li...
阅读全文
摘要:1. for i:=1 to n do swap(a[i], a[random(1,n)]); // 凑合,但不是真正随机2. for i:=1 to n do swap(a[i], a[random(i,n)]); // 真正的随机算法其中,random(a,b)函数用于返回一个从a到b(包括a和b)的随机整数。2)的时间复杂度O(n), 空间复杂度O(1);
阅读全文
摘要:Maximum Depth of Binary TreeMaximum Depth of Binary TreeGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Solution - RecursionThe recursion algorithm is easy to come up:Perform a DFS (depth-fi
阅读全文
摘要:Exceptions Interview QuestionsQ1) What is an Exception?Ans) The exception is said to be thrown whenever an exceptional event occurs in java which signals that something is not correct with the code written and may give unexpected result. An exceptional event is a occurrence of condition which alters
阅读全文
摘要:synchronized 关键字,代表这个方法加锁,相当于不管哪一个线程A每次运行到这个方法时,都要检查有没有其它正在用这个方法的线程B(或者C D等),有的话要等正在使用这个方法的线程B(或者C D)运行完这个方法后再运行此线程A,没有的话,直接运行它包括两种用法:synchronized 方法和 synchronized 块。 1. synchronized 方法: 通过在方法声明中加入 synchronized关键字来声明 synchronized 方法。如: publicsynchronizedvoid accessVal(int newVal); synchronized ...
阅读全文
摘要:Two way to implement singleton patternpostedSep 12, 2011, 1:35 PMby Akrem AYADI [updatedSep 12, 2011, 2:00 PM]You find bellow the two ways to implemen...
阅读全文
摘要:public interface Permission{ float getFee(Calendar start, Calendar end);}class ParkingLot{ private list freeRegularSpace; private list freeCompactSpace; private list freeHandicappedSpace;public ParkingLot(); public ParkingSpace allocateFreeSpace(ParkingSpaceType pspaceType) { ...
阅读全文