您的位置:首页 > 其它

BST——最短路径

2016-06-13 09:01 302 查看
算法:DFS:

static int sum = 0;
static int max =100;
static int i=0;
public static void pathSum(TreeNode t){
sum += t.value;
   if(t.left == null&&t.right == null){
    if(max > sum)
    max = sum;
    sum -= t.value;
    return;
   }
   if(t.left != null)

    pathSum(t.left);
   if(t.right != null)

    pathSum(t.right);
   
   sum=sum - t.value;
  
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  BST最短路径 dfs