r*r
2 楼
经费可以用来买老尼的镜头... :)
可惜偶快变成n黑了, 还在自己掏钱买c奸的东西.
我要好好想一想.
可惜偶快变成n黑了, 还在自己掏钱买c奸的东西.
我要好好想一想.
c*y
4 楼
orz
baozi!!
baozi!!
r*r
6 楼
好吧. 吃完饭回来发几个双黄的.
p*2
17 楼
preorder这个怎么样?
def preorder(root):
n=root
while n!=None:
print n.val
if n.left!=None:
n=n.left
elif n.right!=None:
n=n.right
else:
while(n.parent!=None and (n!=n.parent.left or n.parent.right==
None)):
n=n.parent
n=n.parent
if(n!=None):
n=n.right
def preorder(root):
n=root
while n!=None:
print n.val
if n.left!=None:
n=n.left
elif n.right!=None:
n=n.right
else:
while(n.parent!=None and (n!=n.parent.left or n.parent.right==
None)):
n=n.parent
n=n.parent
if(n!=None):
n=n.right
l*y
18 楼
re,what a BSO!
v*n
20 楼
orz
chi!
chi!
p*2
23 楼
inorder 这个行不行
def inorder(root):
f=0
n=root
while n!=None:
if f==2:
if n.parent!=None and n==n.parent.left:
f=1
n=n.parent;
elif f==1:
print n.val
if n.right!=None:
f=0
n=n.right
else:
f=2
else:
if n.left!=None:
n=n.left
else:
f=1
def inorder(root):
f=0
n=root
while n!=None:
if f==2:
if n.parent!=None and n==n.parent.left:
f=1
n=n.parent;
elif f==1:
print n.val
if n.right!=None:
f=0
n=n.right
else:
f=2
else:
if n.left!=None:
n=n.left
else:
f=1
p*2
27 楼
postorder?
def postorder(root):
f=0
n=root
while n!=None:
if f==2:
print n.val
if n.parent!=None and n==n.parent.left:
f=1
n=n.parent
elif f==1:
if n.right!=None:
f=0
n=n.right
else:
f=2
else:
if n.left!=None:
n=n.left
else:
f=1
def postorder(root):
f=0
n=root
while n!=None:
if f==2:
print n.val
if n.parent!=None and n==n.parent.left:
f=1
n=n.parent
elif f==1:
if n.right!=None:
f=0
n=n.right
else:
f=2
else:
if n.left!=None:
n=n.left
else:
f=1
p*2
29 楼
按照这个思路又写了一个preorder
def preorder2(root):
f=0
n=root
while n!=None:
if f==2:
if n.parent!=None and n==n.parent.left:
f=1
n=n.parent
elif f==1:
if n.right!=None:
f=0
n=n.right
else:
f=2
else:
print n.val
if n.left!=None:
n=n.left
else:
f=1
def preorder2(root):
f=0
n=root
while n!=None:
if f==2:
if n.parent!=None and n==n.parent.left:
f=1
n=n.parent
elif f==1:
if n.right!=None:
f=0
n=n.right
else:
f=2
else:
print n.val
if n.left!=None:
n=n.left
else:
f=1
L*k
36 楼
re
k*t
38 楼
RE
j*n
40 楼
re
r*n
42 楼
re
S*t
44 楼
re
d*0
48 楼
re
r*n
50 楼
re
T*t
52 楼
我也要
p*2
57 楼
还是不明白。我觉得这是两种算法来解决这个问题呀。我这种算法就是需要这么一个变
量才行。我想应该首先从算法上着手讨论吧?面试的时候肯定也是先说算法,然后写
code,会因为算法需要一个变量就被毙掉?如果同样的算法,当然是应该少用变量了。
这个我能明白。另外就是题目加了很多限制,不能recursion, 不能用stack, 并没有说
不能用一个变量呀。
在loop里面放了这么一个状态机
还有就是这句话什么意思呀?怎么叫人为的弄复杂了?不用这个变量根本不能完成这个
算法呀。你的意思是算法本身就很复杂?
【在 A**l 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: sorry,我是从最后帖子看的,之前没看代码,以为你用了O(n)的额外变量
: 刚才把讨论和代码都看了一遍
: 不过我还是同意楼上的观点,尽可能少用额外变量,在loop里面放了这么一个状态机
: 是人为的把code弄复杂了,象楼上提炼出一个primitive function来简化design是值
: 得赞许的思维方式。
: 除非,你这个遍历是能够证明为效率很高的,大量使用的话可以提高performance
b*g
58 楼
baozi
a*s
59 楼
re包子。
幸福啊
幸福啊
G*e
60 楼
re
l*m
62 楼
re
相关阅读
(SR5) New Sony FE and Zeiss FE lenses in mid OctLeica SL-FF (non-rangefinder) mirrorles system camera!请问哪里买SONY FE 55MM F1.8SONY GC 退现金了metalmetal进来看看CANON ANNOUNCEMENTS COMING IN OCTOBER实体店退货用扫描的receipt可以吧?最近一组毛豆:D板上有什么NIKON TO SONY A6000 LENS ADAPTOR 推荐码?现在可以喊关西价收购a7s吗?K3 + 50 1.8+ flash $650SONY A6000 和 Panasonic G7,应该选哪一个?如何备份大量照片?Sony RX1 II Camera Coming in October 20152015 班夫行 航拍 第三弹!警钟长鸣,本版业余摄影师傅要引以为戒棒大的老巢 ...大家都怎么备份照片1DX greymarket $3899滨州红叶求推荐