剑指offer题解【调整数组顺序使奇数位于偶数前面】
来源:互联网 发布:房产中介网站源码 编辑:程序博客网 时间:2024/04/29 17:44
import java.util.ArrayList;public class Solution { public static int[] reOrderArray(int[] array) { ArrayList<Integer> oddList = new ArrayList<Integer>(); ArrayList<Integer> evenList = new ArrayList<Integer>(); for (int a : array) { if (a % 2 == 0) { evenList.add(a); } else { oddList.add(a); } } oddList.addAll(evenList); int size = oddList.size(); Integer[] inteArr = oddList.toArray(new Integer[size]); for(int i = 0; i < size; i++) { array[i] = inteArr[i].intValue(); } return array; }}
思路是将数组分开,再合并起来。Integer转int,可以使用.intValue()。
0 0
- 剑指offer:调整数组顺序使奇数位于偶数前面
- 剑指offer--调整数组顺序使奇数位于偶数前面
- 剑指offer 调整数组顺序使奇数位于偶数前面
- 《剑指offer》调整数组顺序使奇数位于偶数前面
- 剑指 offer:调整数组顺序使奇数位于偶数前面
- 剑指offer-调整数组顺序使奇数位于偶数前面
- 剑指offer 调整数组顺序使奇数位于偶数前面
- 剑指offer-调整数组顺序使奇数位于偶数前面
- 剑指offer 调整数组顺序使奇数位于偶数前面
- 【剑指offer】调整数组顺序使奇数位于偶数前面
- [剑指offer]调整数组顺序使奇数位于偶数前面
- 剑指offer:调整数组顺序使奇数位于偶数前面
- 【剑指offer】调整数组顺序使奇数位于偶数前面
- 剑指offer|调整数组顺序使奇数位于偶数前面
- 《剑指offer》调整数组顺序使奇数位于偶数前面
- 剑指Offer:调整数组顺序使奇数位于偶数前面
- 剑指offer - 调整数组顺序使奇数位于偶数前面
- 【剑指offer】调整数组顺序使奇数位于偶数前面
- bash sh 用法区别
- ACM第三次练习—1012
- HDU 3336 (KMP)
- Android中EditText的setError文字不显示的问题
- css中的强制换行
- 剑指offer题解【调整数组顺序使奇数位于偶数前面】
- 缓存Redis与Memcached的比较
- swift (Singleton)模式
- Android平台的 Ptrace, 注入, Hook 全攻略
- java中没有2进制的数据类型,对二进制的操作,需要使用共三种操作符
- Android 常见bug汇总
- Servlet——Cookie与Session的对比
- sql多行合并为一行
- 关于jsp的一些问题和解答