寻找旋转排序数组中的最小值 II -LintCode
2017-08-15 09:32
417 查看
假设一个旋转排序的数组其起始位置是未知的(比如0 1 2 4 5 6 7 可能变成是4 5 6 7 0 1 2)。
你需要找到其中最小的元素。
数组中可能存在重复的元素。
样例
给出[4,4,5,6,7,0,1,2] 返回 0
你需要找到其中最小的元素。
数组中可能存在重复的元素。
样例
给出[4,4,5,6,7,0,1,2] 返回 0
#ifndef C160_H #define C160_H #include<iostream> #include<vector> using namespace std; class Solution { public: /** * @param num: the rotated sorted array * @return: the minimum number in the array */ int findMin(vector<int> &num) { // write your code here int len = num.size(); if (len <= 0) return 0; for (int i = 0; i < len - 1; ++i) { if (num[i]>num[i + 1]) { return num[i + 1]; break; } } return num[0]; } }; #endif
相关文章推荐
- lintcode-160-寻找旋转排序数组中的最小值 II
- lintcode --寻找旋转排序数组中的最小值 II
- LintCode-寻找旋转排序数组中的最小值 II
- lintcode:寻找旋转排序数组中的最小值 II
- LintCode-分治-寻找旋转排序数组中的最小值 II
- 题目:寻找旋转排序数组中的最小值 II
- 寻找旋转排序数组中的最小值 II
- 寻找旋转排序数组中的最小值 II
- lintcode- 寻找旋转排序数组中的最小值-159
- 寻找旋转排序数组中的最小值 II
- 寻找旋转排序数组中的最小值 II
- 寻找旋转排序数组中的最小值 II
- lintcode-寻找旋转排序数组中的最小值 java 需复习
- 寻找旋转排序数组中的最小值——LintCode
- LintCode-剑指Offer-(160)寻找旋转排序数组中的最小值Ⅱ
- lintcode-63-搜索旋转排序数组 II
- 寻找旋转数组中最小的数I和II
- lintcode,寻找旋转排序数组中的最小值
- 寻找旋转排序数组中的最小值
- lintcode 寻找旋转排序数组中的最小值