Java实现-奇偶分割数组
来源:互联网 发布:三国志13pk优化补丁 编辑:程序博客网 时间:2024/05/29 11:16
分割一个整数数组,使得奇数在前偶数在后。
样例
给定 [1, 2, 3, 4]
,返回 [1, 3, 2, 4]
。
挑战
在原数组中完成,不使用额外空间。
public class Solution { /** * @param nums: an array of integers * @return: nothing */ public void partitionArray(int[] nums) { // write your code here; if(nums.length==0)return;int low=0;int high=nums.length-1;while(low<high){while(low<high&&nums[low]%2==1){low++;}while(low<high&&nums[high]%2==0){high--;}if(low<high){int temp=nums[low];nums[low]=nums[high];nums[high]=temp;}} }}
阅读全文
0 0
- Java实现-奇偶分割数组
- 题目:奇偶分割数组
- 奇偶分割数组
- LintCode_373_奇偶分割数组
- 奇偶分割数组
- lintcode ----奇偶分割数组
- 奇偶分割数组
- 奇偶分割数组
- lintcode,奇偶分割数组
- LintCode373:奇偶分割数组
- 奇偶分割数组
- 奇偶分割数组
- 奇偶分割数组
- Lintcode奇偶分割数组
- 奇偶分割数组-LintCode
- lintcode-奇偶分割数组-373
- 奇偶分割数组(LintCode)
- 奇偶数组分割,原地进行
- Error Limit and Limit Switch Errors Resolving Error Limit Errors An error limit error occurs when
- 如何解决svn Authorization failed错误
- js中apply和call的应用
- APP接口开发小结
- php计算当前时间到下个月的剩余天数
- Java实现-奇偶分割数组
- hadoop系列之六hadoop hdfs操作javaAPI错误记录
- 金典——词频统计
- ubuntu下安装dlib
- 开发手记--android布局用占位符%1$s
- c++ STL
- SpringMVC 表单验证
- js中prototype的理解
- Python之集合,字典 迭代器