May 2009 - May 2017 论坛八周年-你的足迹,我的骄傲



查看: 1349|回复: 0


[复制链接] |试试Instant~ |关注本帖
ziningxiao2 发表于 2015-3-22 23:03:51 | 显示全部楼层 |阅读模式

2015(1-3月) 码农类 硕士 全职@Amazon - 网上海投 - 技术电面 |Other


您需要 登录 才可以下载或查看,没有帐号?获取更多干活,快来注册

A binary tree is either an empty tree (represented by an empty pointer) or a
node consisting of a single integer value and two binary trees called the
left subtree and right subtree.
A binary tree T is given. A path in tree T is a non-empty sequence of nodes
of tree T such that each consecutive node in the sequence is a subtree of
its preceding node.
A path P in tree T is given. The amplitude of path P is the maximum . 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
difference between values of nodes on path P. The amplitude of tree T is the
maximum amplitude of paths in T. If tree T is empty, then it does not have
any paths and its amplitude is assumed to be 0.
For example, consider the following tree T consisting of nine nodes:
Sequence [9, 8, 2] is a path in this tree. Sequence [12, 8, 2] is not a path
in this tree. Path [5, 8, 2] has amplitude 6. Paths [9, 8, 2] and [5, 8, 12
] have amplitude 7. The amplitude of the tree is 7, as no path in it has
amplitude greater than [9, 8, 2] or [5, 8, 12].
Assume that the following declarations are given:
class Tree {
  public int x;
  public Tree l;
  public Tree r;-google 1point3acres
Write a function:
class Solution { public int solution(Tree T); }. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
that, given a tree T consisting of N nodes, returns the amplitude of T.-google 1point3acres
For example, given tree T shown in the example above, the function should
return 7.
Assume that:. From 1point 3acres bbs
·    N is an integer within the range [0..1,000,000];
·    each element of tree T is an integer within the range [−1,000,
Complexity: 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
·    expected worst-case time complexity is O(N);
·    expected worst-case space complexity is O(N).
// you can also use imports, for example:
// import java.math.*;. more info on
class Solution {
    public int solution(Tree T) {
        // write your code in Java SE 6
    }. visit for more.



一亩三分地推荐上一条 /5 下一条

手机版|小黑屋|一亩三分地论坛声明 ( 沪ICP备11015994号 )

custom counter

GMT+8, 2017-5-28 01:43

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

快速回复 返回顶部 返回列表