摘要: ``` # 动态规划 # 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) 编辑
回到页首