sduwangtong
BAN USERdistance of any node to any other node that is below it. Assume: n2 is below n1.
Dist(n1, n2) = Dist(root, n1) + Dist(root, n2) - 2*Dist(root, lca)
in this, Dist(n1, n2) = Dist(root, n2) - Dist(root, n1)
Better than others
- sduwangtong December 16, 2014valid iff BST
- sduwangtong December 14, 2014public int sqrt(int x) {
if(x<0) return -1;
if(x==0) return 0;
int l=1;
int r=x/2+1;
while(l<=r)
{
int m = (l+r)/2;
if(m<=x/m && x/(m+1)<m+1)
return m;
if(x/m<m)
{
r = m-1;
}
else
{
l = m+1;
}
}
return 0;
}
/*
* Replace all single occurrences of "a" with "the"
*/
public class epic_OA_replaceAwithThe {
public static String replace (String input) {
String[] inputSplit = input.split(" a");
input = inputSplit[0];
for(int i=1; i<inputSplit.length; i++) {
input += " the"+inputSplit[i];
}
return input;
}
public static void main(String[] arges) {
System.out.println(replace("This is a English nove, which is a magic"));
}
}
Could you please giving the implementation or code using BFS? I think you are right!
- sduwangtong October 24, 2014
The best answer
- sduwangtong December 21, 2014