一亩三分地论坛

 找回密码
 获取更多干货,去instant注册!

扫码关注一亩三分地公众号
查看: 951|回复: 0
收起左侧

求问一道Amazon的题目

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

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

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看,没有帐号?获取更多干货,去instant注册!

x
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 .1point3acres缃
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 . from: 1point3acres.com/bbs
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;
}
Write a function:
class Solution { public int solution(Tree T); }
that, given a tree T consisting of N nodes, returns the amplitude of T.
For example, given tree T shown in the example above, the function should
return 7.. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷
Assume that:
·    N is an integer within the range [0..1,000,000];
·    each element of tree T is an integer within the range [−1,000,
000,000..1,000,000,000].
Complexity:. From 1point 3acres bbs
·    expected worst-case time complexity is O(N);. From 1point 3acres bbs
·    expected worst-case space complexity is O(N).
// you can also use imports, for example:-google 1point3acres
// import java.math.*;. 1point 3acres 璁哄潧
class Solution {
    public int solution(Tree T) {
        // write your code in Java SE 6
    }
}

本版积分规则

请点这里访问我们的新网站:一亩三分地Instant.

Instant搜索更强大,不扣积分,内容组织的更好更整洁!目前仍在beta版本,努力完善中!反馈请点这里

关闭

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

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

custom counter

GMT+8, 2016-12-7 04:14

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

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