lintcode-easy-Partition Array by Odd and Even
2016-03-03 08:12
567 查看
Partition an integers array into odd number first and even number second.
Given
Given
[1, 2, 3, 4], return
[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 == null || nums.length <= 1) return; int left = 0; int right = nums.length - 1; while(true){ while(left < right && nums[left] % 2 != 0) left++; while(left < right && nums[right] % 2 == 0) right--; if(left == right) break; swap(nums, left, right); } return; } public void swap(int[] nums, int i, int j){ int temp = nums[i]; nums[i] = nums[j]; nums[j] = temp; return; } }
相关文章推荐
- hdu:4035Maze
- DDOS--SYN Flood攻击与防御
- LinkList模拟栈的操作以及模拟队列的操作
- mysql的基本使用方法
- Android Studio首次运行卡在Fetching android SDK compoment information
- 初学Jquery easyui后台框架基础所了解的知识和注意要点
- 2014 android毕设代做 代做Android毕设 安卓毕设
- 【BZOJ 1033】 [ZJOI2008]杀蚂蚁antbuster
- cloudstack4.4新增功能前瞻
- android开发步步为营之65:解决ScrollView和ListView触摸事件onInterceptTouchEvent相互冲突问题
- 网络问题勘查
- 出差教训
- 出差教训
- iOS 下实际网络连接状态
- lintcode-easy-O(1) Check Power of 2
- hive窗口函数理解加实践
- lintcode-easy-Number of Islands
- 【bzoj2085】[Poi2010]Hamsters hash+倍增
- 国际情商12项
- iOS --- 两个NSIndexPath对象的正确比较方式