在 Python3 中,input()获取用户输入,不论用户输入的是什么,获取到的都是字符串类型的。 在 Python2 中有 raw_input()和 input(), raw_input()和 Python3 中的 input()作用是一样的,input()输入的是什...
class Parent(object) x = 1 class Child1(Parent): pass class Child2(Parent): pass print Parent.x, Childx, Childx Childx = 2 print parent.x, Childx, Childx parent.x = 3 print Parent.x, Childx, Childx 结果为: 1 1 1 #继承自父类的类属...
print 方法默认调用 sys.stdout.write 方法,即往控制台打印字符串。...
方法一: a = a+bb = a-ba = a-b 方法二: a = a^b b =b^a a = a^b 方法三: a,b = b,a...
class Anagram: """ @:param s1: The first string @:param s2: The second string @:return true or false """ def Solution1(s1,s2): alist = list(s2) pos1 = 0 stillOK = True while pos1...
class Node(object): def __init__(self, data=None, next=None): self.data = data self.next = nextlink = Node(1, Node(2, Node(3, Node(4, Node(5, Node(6, Node(7, Node(8, Node(9)))))))))def rev(link): pre = link cur = link.next pre.next = None w...
推荐: http://blog.csdn.net/hinyunsin/article/details/6315502 def rebuild(pre, center): if not pre: return cur = Node(pre[0]) index = center.index(pre[0]) cur.left = rebuild(pre[1:index + 1], center[:index]) cur.right = rebuild(pre[index +...
def isSameTree(p, q): if p == None and q == None: return True elif p and q : return p.val == q.val and isSameTree(p.left,q.left) and isSameTree(p.right,q.right) else : return False...
def maxDepth(root): if not root: return 0 return max(maxDepth(root.left), maxDepth(root.right)) + 1...