博客
关于我
牛客网算法——名企高频面试题143题(11)
阅读量:393 次
发布时间:2019-03-04

本文共 1312 字,大约阅读时间需要 4 分钟。

???????????????????????????????????????????????????????????????

????

???????????????????????????????????????????

  • ??????????????? getMax???????????????????????
  • ?????? getMax ???????????????????????
  • ??????????????????????????????????????????????????????????????????????????
  • ????????????????????????????????????
  • ??????????????????????????
  • ????

    package ????;public class ??????? {    public class TreeNode {        int val = 0;        TreeNode left = null;        TreeNode right = null;    }    private int res = Integer.MIN_VALUE;    public int TreeMax(TreeNode root) {        if (root == null) {            return 0;        }        getMax(root);        return res;    }    private int getMax(TreeNode root) {        if (root == null) {            return 0;        }        int left = getMax(root.left);        int right = getMax(root.right);        int current = Math.max(left, right, left + right + root.val);        res = Math.max(res, current);        return current;    }}

    ????

  • TreeNode ??????????????????????????
  • TreeMax ???????????????
    • TreeMax ??????????? res ? Integer.MIN_VALUE??? getMax ????????
  • getMax ???
    • ?????????????? null??? 0?
    • ???????????????????????
    • ???????????? Math.max ??????????????????? res?
    • ???????????????????
  • ???????????????????????????????????????????? O(n)??????? O(h)??? n ?????h ??????

    转载地址:http://emch.baihongyu.com/

    你可能感兴趣的文章
    nodejs-mime类型
    查看>>
    NodeJs——(11)控制权转移next
    查看>>
    NodeJS、NPM安装配置步骤(windows版本)
    查看>>
    NodeJS、NPM安装配置步骤(windows版本)
    查看>>
    nodejs与javascript中的aes加密
    查看>>
    nodejs中Express 路由统一设置缓存的小技巧
    查看>>
    Nodejs中的fs模块的使用
    查看>>
    nodejs包管理工具对比:npm、Yarn、cnpm、npx
    查看>>
    NodeJs单元测试之 API性能测试
    查看>>
    nodejs图片转换字节保存
    查看>>
    nodejs字符与字节之间的转换
    查看>>
    NodeJs学习笔记001--npm换源
    查看>>
    NodeJs学习笔记002--npm常用命令详解
    查看>>
    nodejs学习笔记一——nodejs安装
    查看>>
    NodeJS实现跨域的方法( 4种 )
    查看>>
    nodejs封装http请求
    查看>>
    nodejs常用组件
    查看>>
    nodejs开发公众号报错 40164,白名单配置找不到,竟然是这个原因
    查看>>
    Nodejs异步回调的处理方法总结
    查看>>
    NodeJS报错 Fatal error: ENOSPC: System limit for number of file watchers reached, watch ‘...path...‘
    查看>>