博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
牛客网 旋转数组的最小值
阅读量:4171 次
发布时间:2019-05-26

本文共 837 字,大约阅读时间需要 2 分钟。

题目:旋转数组的最小值

把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。 输入一个非减排序的数组的一个旋转,输出旋转数组的最小元素。 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。 NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。

第一种思路是提交了的代码中的最上边的几种解法

第二种思路来自于一本书,总体是采用的二分的思想,考虑二分之后最小值可能所处的位置

class Solution:    def minNumberInRotateArray(self, rotateArray):        # write code here        pre = -7e20        for num in rotateArray:            if num < pre:                return num            pre = num        if len(rotateArray) == 0:            return 0        return rotateArray[0]    # 二分的思路    def minNumberInRotateArray2(self, rotateArray):        low=0        high=len(rotateArray)-1        mid=0        while low
rotateArray[mid]): high=mid continue if rotateArray[mid]>rotateArray[high]: low=mid continue while low

转载地址:http://wryai.baihongyu.com/

你可能感兴趣的文章
Oracle Apps DBA Interview Questions
查看>>
简单屏幕锁(Simple Screen Locker) 1.1.6.16
查看>>
Bash String Manipulation Examples – Length, Substring, Find and Replace
查看>>
String Operations in Shell
查看>>
烦请解释一下“驱动表”的概念
查看>>
IPAide(IP助手) v1.01
查看>>
Oracle 11g RAC SCAN basics
查看>>
ASM appears to be running, but connect via sqlplus, says idle instance.??
查看>>
Oracle EBS R12 - Steps and Issues/Resolutions during R12.1.1 to R12.1.3 Upgration
查看>>
HW的最后一轮面试
查看>>
简易Python电话本(Simple Python Telephone Book)
查看>>
经典影视日语
查看>>
JPad 1.00(20081213)
查看>>
test the difference between "DEFAULT NULL" and "DEFAULT 0"
查看>>
一个非常方便好用的ADO数据库连接字符串生成工具
查看>>
轻松得到C# ADO.NET的各种数据库连接字符串
查看>>
DLL文件制作与在VBA调用初级进阶
查看>>
Excel VBA: Delete Module After Running VBA Code. Deleting Modules via VBA Code
查看>>
SQLPLUS 使用的一些技巧
查看>>
excel 宏表函数 get.cell
查看>>