一亩三分地论坛

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

一亩三分地官方iOS手机应用下载
查看: 1227|回复: 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
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 .鏈枃鍘熷垱鑷1point3acres璁哄潧
any paths and its amplitude is assumed to be 0.
For example, consider the following tree T consisting of nine nodes:-google 1point3acres
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 {. Waral 鍗氬鏈夋洿澶氭枃绔,
  public int x;
  public Tree l;
  public Tree r;
}
Write a function:. 1point 3acres 璁哄潧
class Solution { public int solution(Tree T); }. 1point3acres.com/bbs
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,. visit 1point3acres.com for more.
000,000..1,000,000,000].
Complexity:. from: 1point3acres.com/bbs
·    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.*;
class Solution {
    public int solution(Tree T) {.1point3acres缃
        // write your code in Java SE 6
    }
}. 1point 3acres 璁哄潧

本版积分规则

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

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

关闭

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

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

custom counter

GMT+8, 2017-3-30 07:08

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

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