Redian新闻
>
Ooma Telo White $58.77 at Amazon
avatar
Ooma Telo White $58.77 at Amazon# PDA - 掌中宝
g*r
1
Career Cup上看到的,虽然是两年前的老题了,大家做做?
Consider this string representation for binary trees. Each node is of the
form (lr), where l represents the left child and r represents the right
child. If l is the character 0, then there is no left child. Similarly, if r
is the character 0, then there is no right child. Otherwise, the child can
be a node of the form (lr), and the representation continues recursively.
For example: (00) is a tree that consists of one node. ((00)0) is a two-node
tree in which the root has a left child, and the left child is a leaf. And
((00)(00)) is a three-node tree, with a root, a left and a right child.
Write a function that takes as input such a string, and returns -1 if the
string is malformed, and the depth of the tree if the string is well-formed.
For instance:
find_depth('(00)') -> 0
find_depth('((00)0)') -> 1
find_depth('((00)(00))') -> 1
find_depth('((00)(0(00)))') -> 2
find_depth('((00)(0(0(00))))') -> 3
find_depth('x') -> -1
find_depth('0') -> -1
find_depth('()') -> -1
find_depth('(0)') -> -1
find_depth('(00)x') -> -1
find_depth('(0p)') -> -1
avatar
r*c
2
如题
avatar
m*d
3
avatar
j*u
4
历史最低!各位这货有什么用?
avatar
y*1
5
感觉就是一边扫一边check是不是valid,然后用算深度最深的括号有几层
avatar
t*e
6
同问

【在 r***c 的大作中提到】
: 如题
avatar
f*p
7
神马失重,其实就是个充气娃娃!你老婆HIGH的时候,也这样子!
avatar
f*t
8
// Consider this string representation for binary trees. Each node is of the
// form (lr), where l represents the left child and r represents the right
// child. If l is the character 0, then there is no left child. Similarly,
if r
// is the character 0, then there is no right child. Otherwise, the child
can
// be a node of the form (lr), and the representation continues recursively.
// For example: (00) is a tree that consists of one node. ((00)0) is a two-
node
// tree in which the root has a left child, and the left child is a leaf.
And
// ((00)(00)) is a three-node tree, with a root, a left and a right child.
int TreeDepth(const char **str) {
if ('(' != **str) {
return -1;
}
++*str;
int left = 0, right = 0;
//left child
if (**str == '(') {
if (-1 == (left = TreeDepth(str))) {
return -1;
}
} else if (**str == '0') {
left = 0;
++*str;
} else {
return -1;
}
//right child
if (**str == '(') {
if (-1 == (right = TreeDepth(str))) {
return -1;
}
} else if (**str == '0') {
right = 0;
++*str;
} else {
return -1;
}
//end
if (**str == ')') {
++*str;
return 1 + max(left, right);
} else {
return -1;
}
}
int find_depth(const char *str) {
int res = TreeDepth(&str);
return *str == '
avatar
i*g
10
你们家充气娃娃这么逼真

【在 f****p 的大作中提到】
: 神马失重,其实就是个充气娃娃!你老婆HIGH的时候,也这样子!
avatar
s*y
12
这个是真的,Kate Upton, 几个星期天yahoo 刚报道。
她被拉到一个模拟zero gravity 的飞机上照的

【在 m**d 的大作中提到】

avatar
c*r
13
Kate Upton为SI拍的视频

【在 f****p 的大作中提到】
: 神马失重,其实就是个充气娃娃!你老婆HIGH的时候,也这样子!
avatar
M*P
14
关键是失重情况下是否还硬的起来

★ 发自iPhone App: ChineseWeb 7.8

【在 m**d 的大作中提到】

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。