cracking code 4.8

// find a path in the tree, sum up to a value, the path is not necessary start at root
void findPath( TreeNode root, int sum, ArrayList arr, int level )
// base case check
if( root == null )

arr.add( );
int temp = sum;
for( int i = level; i > -1; i– )
temp -= arr.get( i );
ArrayList arrClone1 = arr.clone();
ArrayList arrClone2 = arr.clone();

findPath( roo->left, sum, arrClone1, level+1 );
findPath( roo->right, sum, arrClone2, level+1 );

This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s