上一页 1 2 3 4 5 6 7 8 9 10 ··· 13 下一页
摘要: ``` #主要是考虑边界情况 def power(base, exponent): if base == 0 and exponent < 0: return 0 absexponent = exponent if exponent < 0: absexponent = -exponent result = powerWithExponent(base, absexponent) if expon 阅读全文
posted @ 2020-04-24 13:48 烧刘病 阅读(69) 评论(0) 推荐(0) 编辑
摘要: ``` # 动态规划 # 1.最优解;2.分解成子问题 # 比如算f(8) 就把 f(1)f(7) f(2)f(6) f(3)f(5) f(4)f(4) 之前算出来的数字 重新算一遍即可 def maxProductAfterCutting_solution1(lenth): if lenth == 0 or lenth == 1: return 0 if lenth == 2: return 1 阅读全文
posted @ 2020-04-23 15:53 烧刘病 阅读(114) 评论(0) 推荐(0) 编辑
摘要: ``` # 位运算 # 思路:把该number的左右边的1-1变为0,1后面的0变为1;在于number & 的话就消除一个1,循环消1 即可 def numberof_inbinary(number): count = 0 while number: count += 1 number = (number - 1) & number # 本质是在消除1的过程 return count ``` 阅读全文
posted @ 2020-04-23 15:40 烧刘病 阅读(48) 评论(0) 推荐(0) 编辑
摘要: ``` def moveCount(threshold, rows, cols): if threshold = 0 and row >= 0 and col 0: sum += number % 10 number //= 10 return sum #递归的思想 #1.row col 0 0 check(0,0)=True #赋值visited;递归-1 0 false return 0 递归 阅读全文
posted @ 2020-04-23 14:01 烧刘病 阅读(91) 评论(0) 推荐(0) 编辑
摘要: ```def haspathCore(martrix, rows, cols, row, col, visited, findstr, pathlenth): # cur_ch=findstr[pathlenth] if pathlenth == len(findstr): # 找到最后一个字符停止查找 return True hasPath = False ... 阅读全文
posted @ 2020-04-23 11:13 烧刘病 阅读(62) 评论(0) 推荐(0) 编辑
摘要: ``` def get_min(li): low = 0 high = len(li) - 1 mid = low while li[low] >= li[high]: # 一般low的元素>=high的元素 if high - low == 1: mid = high break if (li[low] == li[high] and li[mid] == li[low]): # 特殊情况:无法 阅读全文
posted @ 2020-04-22 15:24 烧刘病 阅读(74) 评论(0) 推荐(0) 编辑
摘要: ```# 二分查找def bin_search(li, val): # 有序列表 low = 0 high = len(li)-1 while low val: high = mid - 1 else: # li[mid]<val low = mid + 1 return -1``` 阅读全文
posted @ 2020-04-21 10:38 烧刘病 阅读(83) 评论(0) 推荐(0) 编辑
摘要: ``` def fibbonacci(n): if not isinstance(n, int): raise ValueError('n is int type') resulet = [0, 1] if n in resulet: return resulet[n] fibbo2 = 0 # n-2的项 fibbo1 = 1 # n-1的项 fibbon = 0 # n for i in ra 阅读全文
posted @ 2020-04-21 10:16 烧刘病 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 什 么 都 看 不 见 阅读全文
posted @ 2020-04-20 16:37 烧刘病 阅读(109) 评论(0) 推荐(0) 编辑
摘要: ``` # 二叉树 class BiTreeNode: def __init__(self, data): self.data = data self.lchild = None self.rchild = None a = BiTreeNode('A') b = BiTreeNode('B') c = BiTreeNode('C') d = BiTreeNode('D') e = BiTreeN 阅读全文
posted @ 2020-04-20 10:31 烧刘病 阅读(127) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 13 下一页
回到页首