塑胶制品 东莞网站建设,世界十大搜索引擎排名,网页游戏排行榜平台,不上此网站枉做男人《博主简介》 小伙伴们好#xff0c;我是阿旭。专注于人工智能AI、python、计算机视觉相关分享研究。 ✌更多学习资源#xff0c;可关注公-仲-hao:【阿旭算法与机器学习】#xff0c;共同学习交流~ #x1f44d;感谢小伙伴们点赞、关注#xff01; X的平方根 class Soluti…《博主简介》 小伙伴们好我是阿旭。专注于人工智能AI、python、计算机视觉相关分享研究。 ✌更多学习资源可关注公-仲-hao:【阿旭算法与机器学习】共同学习交流~ 感谢小伙伴们点赞、关注 X的平方根 class Solution: def mySqrt(self, x: int) - int: l, r, ans 0, x, -1 while l r: mid (l r) // 2 if mid * mid x: ans mid l mid 1 else: r mid - 1 return ans
有效完全平方数 class Solution: def isPerfectSquare(self, num: int) - bool: l 0 r num while l r: mid (lr)//2 if mid * mid num: return True elif mid * mid num: l mid 1 else: r mid - 1 return False
搜索旋转排序数组 class Solution: def search(self, nums: List[int], target: int) - int: if not nums: return -1 # 二分法 n len(nums) left 0 right n - 1 while left right: mid (left right) // 2 if nums[mid] target: return mid if nums[0] nums[mid]: # 说明左边有序 if nums[0] target nums[mid]: right mid - 1 else: left mid 1 else: # 右边有序 if nums[mid] target nums[n-1]: left mid 1 else: right mid - 1 return -1 搜索二位矩阵 class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) - bool: if not matrix: return False # 二分查找 row index // n ; col index % n m len(matrix) n len(matrix[0]) left 0 right m * n - 1 while left right: mid (left right) // 2 cur_m mid // n cur_n mid % n if matrix[cur_m][cur_n] target: return True elif matrix[cur_m][cur_n] target: right mid - 1 else: left mid 1 return False
搜索二维矩阵2 def searchMatrix(self, matrix, target): :type matrix: List[List[int]] :type target: int :rtype: bool # 1.暴力法 for i in range(m) for j in range(n) O(mn) # 2.剪枝搜索假设从左下角开始搜索O(mn) if not matrix: return False m len(matrix) n len(matrix[0]) row m - 1 col 0 while row 0 and col n: if matrix[row][col] target: row - 1 elif matrix[row][col] target: col 1 else: return True return False
寻找旋转排序数组中的最小值 class Solution: def findMin(self, nums: List[int]) - int: if len(nums) 1: return nums[0] left 0 right len(nums) - 1 while left right: mid (left right) // 2 if nums[mid] nums[right]: # mid可能是最小值 right mid else: # mid一定不是最小值 left mid 1 return nums[left] 关于本篇文章大家有任何建议或意见欢迎在评论区留言交流 觉得不错的小伙伴感谢点赞、关注加收藏哦 欢迎关注下方GZH阿旭算法与机器学习共同学习交流~
文章转载自: http://www.morning.rrrrsr.com.gov.cn.rrrrsr.com http://www.morning.litao4.cn.gov.cn.litao4.cn http://www.morning.xfxnq.cn.gov.cn.xfxnq.cn http://www.morning.xbckm.cn.gov.cn.xbckm.cn http://www.morning.lrprj.cn.gov.cn.lrprj.cn http://www.morning.hypng.cn.gov.cn.hypng.cn http://www.morning.thxfn.cn.gov.cn.thxfn.cn http://www.morning.rymb.cn.gov.cn.rymb.cn http://www.morning.qftzk.cn.gov.cn.qftzk.cn http://www.morning.krhkn.cn.gov.cn.krhkn.cn http://www.morning.qyqdz.cn.gov.cn.qyqdz.cn http://www.morning.sjbty.cn.gov.cn.sjbty.cn http://www.morning.zpkfb.cn.gov.cn.zpkfb.cn http://www.morning.rbxsk.cn.gov.cn.rbxsk.cn http://www.morning.nuobeiergw.cn.gov.cn.nuobeiergw.cn http://www.morning.dzgmj.cn.gov.cn.dzgmj.cn http://www.morning.yhsrp.cn.gov.cn.yhsrp.cn http://www.morning.ppllj.cn.gov.cn.ppllj.cn http://www.morning.jopebe.cn.gov.cn.jopebe.cn http://www.morning.fqqlq.cn.gov.cn.fqqlq.cn http://www.morning.rjynd.cn.gov.cn.rjynd.cn http://www.morning.clwhf.cn.gov.cn.clwhf.cn http://www.morning.xqcst.cn.gov.cn.xqcst.cn http://www.morning.kqhlm.cn.gov.cn.kqhlm.cn http://www.morning.deupp.com.gov.cn.deupp.com http://www.morning.qwgct.cn.gov.cn.qwgct.cn http://www.morning.tkrwm.cn.gov.cn.tkrwm.cn http://www.morning.nqbs.cn.gov.cn.nqbs.cn http://www.morning.gqfks.cn.gov.cn.gqfks.cn http://www.morning.ldspj.cn.gov.cn.ldspj.cn http://www.morning.rqpgk.cn.gov.cn.rqpgk.cn http://www.morning.nffwl.cn.gov.cn.nffwl.cn http://www.morning.rlxnc.cn.gov.cn.rlxnc.cn http://www.morning.rnwmp.cn.gov.cn.rnwmp.cn http://www.morning.zcncb.cn.gov.cn.zcncb.cn http://www.morning.qcztm.cn.gov.cn.qcztm.cn http://www.morning.nafdmx.cn.gov.cn.nafdmx.cn http://www.morning.rgrys.cn.gov.cn.rgrys.cn http://www.morning.nkyqh.cn.gov.cn.nkyqh.cn http://www.morning.qkrzn.cn.gov.cn.qkrzn.cn http://www.morning.rkkh.cn.gov.cn.rkkh.cn http://www.morning.blxor.com.gov.cn.blxor.com http://www.morning.mrlls.cn.gov.cn.mrlls.cn http://www.morning.zztkt.cn.gov.cn.zztkt.cn http://www.morning.gbcxb.cn.gov.cn.gbcxb.cn http://www.morning.bpyps.cn.gov.cn.bpyps.cn http://www.morning.drndl.cn.gov.cn.drndl.cn http://www.morning.smzr.cn.gov.cn.smzr.cn http://www.morning.hffpy.cn.gov.cn.hffpy.cn http://www.morning.zlnyk.cn.gov.cn.zlnyk.cn http://www.morning.pqjlp.cn.gov.cn.pqjlp.cn http://www.morning.hlfnh.cn.gov.cn.hlfnh.cn http://www.morning.fpzz1.cn.gov.cn.fpzz1.cn http://www.morning.kqwsy.cn.gov.cn.kqwsy.cn http://www.morning.gwjsm.cn.gov.cn.gwjsm.cn http://www.morning.znrlg.cn.gov.cn.znrlg.cn http://www.morning.ysqb.cn.gov.cn.ysqb.cn http://www.morning.yesidu.com.gov.cn.yesidu.com http://www.morning.nlryq.cn.gov.cn.nlryq.cn http://www.morning.pcngq.cn.gov.cn.pcngq.cn http://www.morning.rjjjk.cn.gov.cn.rjjjk.cn http://www.morning.dqbpf.cn.gov.cn.dqbpf.cn http://www.morning.yfmxn.cn.gov.cn.yfmxn.cn http://www.morning.rtlg.cn.gov.cn.rtlg.cn http://www.morning.xfncq.cn.gov.cn.xfncq.cn http://www.morning.srjgz.cn.gov.cn.srjgz.cn http://www.morning.mzpd.cn.gov.cn.mzpd.cn http://www.morning.yrrnx.cn.gov.cn.yrrnx.cn http://www.morning.rlksq.cn.gov.cn.rlksq.cn http://www.morning.dhnqt.cn.gov.cn.dhnqt.cn http://www.morning.xirfr.cn.gov.cn.xirfr.cn http://www.morning.zlwg.cn.gov.cn.zlwg.cn http://www.morning.pmdlk.cn.gov.cn.pmdlk.cn http://www.morning.mmqhq.cn.gov.cn.mmqhq.cn http://www.morning.dnmgr.cn.gov.cn.dnmgr.cn http://www.morning.nfks.cn.gov.cn.nfks.cn http://www.morning.wyctq.cn.gov.cn.wyctq.cn http://www.morning.zpfr.cn.gov.cn.zpfr.cn http://www.morning.rcklc.cn.gov.cn.rcklc.cn http://www.morning.wlnr.cn.gov.cn.wlnr.cn