srirangr
BAN USERpublic boolean sumTraverse(int N, TreeNode root){
if(root!=null && N - root.data == 0){
return true;
} else if(root.leftChild == null && root.rightChild == null){
return false;
}
if(sumTraverse(N - root.data, root.leftChild)) return true;
else if(sumTraverse(N - root.data, root.rightChild)) return true;
return false;
}
Tested for all edge cases -
public int sumOfAllGreater(TreeNode root, int i){
if(root == null){
return i;
}
else if(root.leftChild == null && root.rightChild == null){
root.data += i;
return root.data;
}
int tmp = sumOfAllGreater(root.rightChild, i);
root.data += tmp;
tmp = sumOfAllGreater(root.leftChild, root.data);
return tmp;
}
Should call sumOfAllGreater(bst.root, 0) initially..
- srirangr May 08, 2012
Reprothymellen, Consultant at Accolite software
I am a Correctional officer . I have the primary role of maintaining order within a detention facility. My hobby is ...
RepSuziCorni, Accountant at A9
I have strong critical and analytical skills with reading, writing, and comprehension. I have exceptional speaking skills without losing train ...
Reprmansummers, Accountant at Alcatel Lucent
I'm Rman! I graduated from the University of Arizona with a Bachelor's degree in Psychology and Education. I ...
Repracheljennir, Personnel consultant at Infinite Wealth
Rachel, I am a Personnel consultant who acts as mediator between employers and job seekers. The main task of I ...
This is a standard problem. Check this out : en.wikipedia.org / wiki / Cutting_stock_problem
- srirangr June 26, 2012