提交 68cf0b8e 编写于 作者: 梦境迷离's avatar 梦境迷离

scala leetcode 563

上级 380054c8
package io.github.dreamylost
/**
* 563. 二叉树的坡度
*
* 563. 二叉树的坡度
*
* 给定一个二叉树,计算整个树的坡度。
*
*
* 一个树的节点的坡度定义即为,该节点左子树的结点之和和右子树结点之和的差的绝对值。空结点的的坡度是0。
*
*
* 整个树的坡度就是其所有节点的坡度之和。
*
*
* @author 梦境迷离 dreamylost
* @since 2020-06-13
* @version v1.0
*/
* @since 2020-06-13
* @version v1.0
*/
object Leetcode_563 extends App {
val ret = findTilt(TreeNodeData.treeData3())
......@@ -37,12 +37,12 @@ object Leetcode_563 extends App {
}
/**
* 972 ms,100.00%
* 52.9 MB,100.00%
*
* 972 ms,100.00%
* 52.9 MB,100.00%
*
* @param root
* @return
*/
* @return
*/
def findTilt(root: TreeNode): Int = {
//3.对当前所有节点进行求度
var allSum = Seq[Int]()
......@@ -53,16 +53,16 @@ object Leetcode_563 extends App {
}
/**
* 668 ms,100.00%
* 52 MB,100.00%
*
* 668 ms,100.00%
* 52 MB,100.00%
*
* @param root
* @return
*/
* @return
*/
def findTilt2(root: TreeNode): Int = {
var sum = 0
//每次返回左右子树
//每次返回左右子树,每次使用左右子树和进行更新sum
def dfs(rt: TreeNode): Int = {
if (rt == null) return 0
val l: Int = dfs(rt.left)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册