Leetcode[154]-Find Minimum in Rotated Sorted Array II
2016-02-01 20:28
423 查看
Link: https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/
Suppose a sorted array is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
Find the minimum element.
The array may contain duplicates.
C++:
方法一:直接遍历求解
Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates are allowed? Would this affect the run-time complexity? How and why?
Suppose a sorted array is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
Find the minimum element.
The array may contain duplicates.
C++:
方法一:直接遍历求解
class Solution { public: int findMin(vector<int>& nums) { int n = nums.size(); int min = nums[0]; for(int i = 1; i < n; i++) { if(nums[i]<min){ min = nums[i]; } } return min; } };
相关文章推荐
- MySQL对数据库,表和表字段或者是记录的基本操作
- 电商为何要死磕线下?
- 五模十频
- Objextive-C入门学习1--使用NSLog函数在屏幕上打印HelloWorld
- 单链表实现行编辑
- mycat读写分离与主从切换
- poj1386Play on Words(欧拉通路)
- iOS UI自动化——Instruments常用语法
- HDU4632 Palindrome subsequence(区间DP)
- Ubuntu安装Vim
- Unity问答第3期
- Javascript的四种(函数)调用模式
- POJ 2590:Steps
- java语言读取xml文本中的内容
- JavaScript菜鸟教程 grammar
- Java抢红包小程序
- java IO回想小结
- hdoj 1527取石子游戏
- 初识算法
- Qt 富文本处理(QTextDocument和QTextBlock和QTextFrame和QTextTable和QTextList和QTextDocument)