剑指offer:旋转数组的最小数字 代码实现
来源:互联网 发布:传奇盛世羽翼进阶数据 编辑:程序博客网 时间:2024/05/09 13:27
题目描述
把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个非递减序列的一个旋转,输出旋转数组的最小元素。例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。
#include <stdio.h>#include <iostream>#include <vector>using namespace std;class Solution {public: void reOrderArray(vector<int> &array) { int array_size = array.size(); int index = 0,j = 0;; vector<int> vecTemp(array.size()); /* 先放奇数 */ for(index = 0; index < array_size; index++) { if(array[index] % 2 == 1) { vecTemp[j++] = array[index]; } } /* 再放偶数 */ for(index = 0; index < array_size; index++) { if(array[index] % 2 == 0) { vecTemp[j++] = array[index]; } } array = vecTemp; }};int main(){ Solution s; int i = 0;// vector<int> vec; vector<int> vec(6); vec[0] = 1; vec[1] = 2; vec[2] = 3; vec[3] = 4; vec[4] = 5; vec[5] = 6; s.reOrderArray(vec); for(i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl; return 0;}
0 0
- 剑指offer:旋转数组的最小数字 代码实现
- 剑指offer:旋转数组的最小数字 代码实现
- 剑指offer----旋转数组的最小数字----java实现
- 【剑指offer】旋转数组的最小数字
- 剑指offer--旋转数组的最小数字
- 剑指offer--旋转数组的最小数字
- 剑指offer:旋转数组的最小数字
- 《剑指offer》旋转数组的最小数字
- 剑指 offer:旋转数组的最小数字
- 剑指offer-旋转数组的最小数字
- 剑指offer 旋转数组的最小数字
- 【剑指offer】旋转数组的最小数字
- 剑指offer 旋转数组的最小数字
- 剑指offer-旋转数组的最小数字
- 剑指Offer:旋转数组的最小数字
- 剑指Offer 旋转数组的最小数字
- 剑指offer|旋转数组的最小数字
- 剑指offer:旋转数组的最小数字
- laravel 5 blade
- 审批流(一)
- 关于vi的一些用法
- 老彭零基础教你学java
- 【Latex】中插入图片(Excel和Visio绘制)不失真的方法
- 剑指offer:旋转数组的最小数字 代码实现
- Letter Combinations of a Phone Number
- 机器学习之无监督特征学习——Unsupervised feature learning and deep learning
- Node.js简介及安装开发环境
- 邮件原理
- C语言 分支结构(Xcode)
- nutch部分引用库
- 博主信息
- poj2010Moo University - Financial Aid