摘要:
1 def gcd(a, b): 2 while a != 0: 3 a, b = b % a, a 4 5 return b 定理:两个整数的最大公约数等于其中较小的那个数和两数相除余数的最大公约数。最大公约数(Greatest Common Divisor)缩写为GCD。 gcd(a,b) = 阅读全文
摘要:
http://blog.codinglabs.org/articles/theory-of-mysql-index.html 阅读全文
摘要:
阅读全文
摘要:
阅读全文
摘要:
阅读全文
摘要:
给定一个数组,构建二叉树,并且按层次打印这个二叉树 ## 14 二叉树节点 class Node(object): def __init__(self, data, left=None, right=None): self.data = data self.left = left self.righ 阅读全文
摘要:
1 def quick_sort(arr): 2 if len(arr) <= 1: 3 return arr 4 else: 5 base = arr[0] 6 less = [v for v in arr[1:] if v<=base] 7 more = [v for v in arr[1:] 阅读全文
摘要:
二分查找 1 def binarySearch(l, t): 2 low, high = 0, len(l) - 1 3 while low < high: 4 print low, high 5 mid = (low + high) / 2 6 if l[mid] > t: 7 high = mi 阅读全文
摘要:
交叉链表求交点 1 class ListNode: 2 def __init__(self, x): 3 self.val = x 4 self.next = None 5 def node(l1, l2): 6 length1, lenth2 = 0, 0 7 # 求两个链表长度 8 while 阅读全文
摘要:
1.尾递归 1 def _recursion_merge_sort2(l1, l2, tmp): 2 if len(l1) == 0 or len(l2) == 0: 3 tmp.extend(l1) 4 tmp.extend(l2) 5 return tmp 6 else: 7 if l1[0] 阅读全文