IT入门 > 面试题 > python题库 > 编程题 >
  • 快速排序

    2019/07/27 点击:1105

    #coding:utf-8def quicksort(list): if len(list) midpivot] finallylist = quicksort(lessbeforemidpivot)+[midpivot]+quicksort(biggerafterpivot) return finallylistprint quicksort([2,4,6,7,1,2,5]) 更多排序问题可见:[数据结构与算法

  • 找零问题

    2019/07/27 点击:3531

    #coding:utf-8#values是硬币的面值values = [ 25, 21, 10, 5, 1]#valuesCounts 钱币对应的种类数#money 找出来的总钱数#coinsUsed 对应于目前钱币总数i所使用的硬币数目def coinChange(values,valuesCounts,money,coin

  • 广度遍历和深度遍历二叉树

    2019/07/27 点击:6704

    给定一个数组,构建二叉树,并且按层次打印这个二叉树

  • 二叉树节点

    2019/07/27 点击:1960

    class Node(object): def __init__(self, data, left=None, right=None): self.data = data self.left = left self.right = righttree = Node(1, Node(3, Node(7, Node(0)), Node(6)), Node(2, Node(5), Node(4)))

  • 深度遍历

    2019/07/27 点击:2259

    def deep(root): if not root: return print root.data deep(root.left) deep(root.right)if __name__ == '__main__': lookup(tree) deep(tree)

  • 前中后序遍历

    2019/07/27 点击:4292

    深度遍历改变顺序就OK了 #coding:utf-8#二叉树的遍历#简单的二叉树节点类class Node(object): def __init__(self,value,left,right): self.value = value self.left = left self.right = right#中序遍历:遍历左子树,访问当

  • 求最大树深

    2019/07/27 点击:7072

    def maxDepth(root): if not root: return 0 return max(maxDepth(root.left), maxDepth(root.right)) + 1

  • 求两棵树是否相同

    2019/07/27 点击:1828

    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

  • 前序中序求后序

    2019/07/27 点击:6964

    推荐: 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 +

  • 单链表逆置

    2019/07/27 点击:2085

    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