奇偶分割数组-LintCode
来源:互联网 发布:单身 快乐 知乎 编辑:程序博客网 时间:2024/05/29 09:56
分割一个整数数组,使得奇数在前偶数在后。
样例:
给定 [1, 2, 3, 4],返回 [1, 3, 2, 4]。
挑战:
在原数组中完成,不使用额外空间。
#ifndef C373_H#define C373_H#include<iostream>#include<vector>using namespace std;class Solution {public: /* * @param nums: an array of integers * @return: nothing */ void partitionArray(vector<int> &nums) { // write your code here int i = 0; int j = nums.size()-1; while (i<j) { if (nums[i] %2 == 0 && nums[j] %2!=0) { swap(nums[i], nums[j]); i++; j--; } if (nums[i] %2!=0) i++; if (nums[j] %2 == 0) j--; } }};#endif
阅读全文
0 0
- lintcode ----奇偶分割数组
- lintcode,奇偶分割数组
- Lintcode奇偶分割数组
- 奇偶分割数组-LintCode
- lintcode-奇偶分割数组-373
- 奇偶分割数组(LintCode)
- [LintCode]373.奇偶分割数组
- LintCode-剑指Offer-(373)奇偶分割数组
- 题目:奇偶分割数组
- 奇偶分割数组
- LintCode_373_奇偶分割数组
- 奇偶分割数组
- 奇偶分割数组
- 奇偶分割数组
- LintCode373:奇偶分割数组
- 奇偶分割数组
- 奇偶分割数组
- 奇偶分割数组
- Android Studio 中修改versionCode跟versionName (更新版本)
- JAVA Spring报错 (1)
- Linux乌班图终端操作SVN
- 一台电脑运行多个Tomcat---Windows
- Java 字符串判断为空总结
- 奇偶分割数组-LintCode
- Ext.net 底层查看
- PMM出问题排查
- 解读Spring的入口(针对SpringBoot)
- linux 下查看机器是cpu是几核的
- Unity 自定义Inspector界面。 延时 对 对象的 一些 基本操作。
- Java
- 如何读懂火焰
- ios react native 手动配置 realm 使用cocoapods 会编译报错 fatal error: 'React/RCTBridge.h' file not found