zoukankan      html  css  js  c++  java
  • 剑指offer6:旋转数组的最小数字

    1. 题目描述

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

    2. 思路和方法

      排序和并找到最小值,可以用sort函数。

    3. C++代码

    1 class Solution {
    2 public:
    3     int minNumberInRotateArray(vector<int> rotateArray) {
    4         sort(rotateArray.begin(),rotateArray.end());
    5         return rotateArray[0];
    6     }
    7 };
    View Code
  • 相关阅读:
    页码数求0到9共有多少个
    reduce
    map,filter
    匿名函数 lambda
    递归
    python 切片
    函数
    集合(set)
    python 中random 库的使用
    printf 输出?
  • 原文地址:https://www.cnblogs.com/wxwhnu/p/11406587.html
Copyright © 2011-2022 走看看