Python 刷Leetcode题库,顺带学英语单词(38)
Find Peak Element
A peak element is an element that is greater than its neighbors.
Given an input array nums , where nums[i] ≠ nums[i+1] , find a peak element and return its index.
The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.
You may imagine that nums[-1] = nums[n] = -∞ . [#162]
Examples:
Input: nums = [1,2,3,1]
Output: 2
Explanation: 3 is a peak element and your function should return the index number 2.Input: nums = [1,2,1,3,5,6,4]
Output: 1 or 5
Explanation: Your function can return either index number 1 where the peak element is 2, or index number 5 where the peak element is 6.
Note:
Your solution should be in logarithmic complexity.
Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted form. [#164]
Return 0 if the array contains less than 2 elements.
Example 1:
Input: [3,6,9,1]
Output: 3
Explanation: The sorted form of the array is [1,3,6,9], either (3,6) or (6,9) has the maximum difference 3.
Example 2:
Input: [10]
Output: 0
Explanation: The array contains less than 2 elements, therefore return 0.
Note:
You may assume all elements in the array are non-negative integers and fit in the 32-bit signed integer range.
Try to solve it in linear time/space.
相关文章
- Python 编程 | 连载 11 - Python 集合
- mt4 python_一个使用Python自动化交易外汇MT4脚本实现「建议收藏」
- python字符串转化列表_Python列表到字符串的转换[通俗易懂]
- python中dtype的使用规范_Python numpy.dtype() 使用实例
- python截图识别文字_Python文字截图识别OCR工具实例解析
- python在线代码编辑器-5种最佳Python IDE和代码编辑器
- 【说站】python如何使用send唤醒
- python lambda表达式 if_Python学习-lambda表达式
- python里面的缩进是什么意思_Python缩进规则(一看即懂)[通俗易懂]
- python django 数据库_Apache+Mysql+PHP/Python简单项目
- python win32api sendmessage_Python win32api.SendMessage方法代码示例[通俗易懂]
- Python 生成随机数_python 随机字符串
- python绘制条形柱状图_Python柱状图
- eval在python中是什么意思_如何在Python中使用eval ?
- 2020 GO vs Python 应该选择哪一个
- 一个超级神奇的 Python 第三方库
- 手把手教你MacOS系统下Python的安装和配置
- Python 图像边缘检测 | 利用 opencv 和 skimage 的 Canny 算法
- 使用python的随机森林算法处理遥感数据
- Python内置函数一览表
- Python raise用法(超级详细,看了无师自通)
- Python模拟键盘输入和鼠标操作详解编程语言
- 基于Python的Android图形锁破解程序详解编程语言
- python:Functional Programming详解编程语言
- python学习Linux、Python,体验自由的乐趣(lexlinux)
- pythonMSSQL数据挖掘:从MSSQL外延到Python(mssqlinto)
- Connecting to MSSQL with Python: A Comprehensive Guide for Beginners(python连接mssql)
- 革命性技术:Python与MSSQL的携手合作(python和mssql)
- Python编程连接MySQL:从零开始(python与mysql)
- Python脚本实现Linux命令快捷控制(python执行linux命令)
- Python中列表、字典、元组、集合数据结构整理