首页 > 编程语言 > 详细

LeetCode-922 Sort Array By Parity II Solution (with Java)

时间:2020-03-02 17:07:03      阅读:66      评论:0      收藏:0      [点我收藏+]

1. Description:

技术分享图片

Notes:

技术分享图片

2. Examples:

技术分享图片

3.Solutions:

 1 /**
 2  * Created by sheepcore on 2019-02-24
 3  */
 4 class Solution {
 5     public int[] sortArrayByParityII(int[] A) {
 6       int k = 0, j = 1;
 7         int[] res = new int[A.length];
 8         for (int i = 0; i < A.length; i++) {
 9             if (A[i] % 2 == 0) {
10                 res[k] = A[i];
11                 k += 2;
12             } else {
13                 res[j] = A[i];
14                 j += 2;
15             }
16         }
17         return res;
18     }
19 }

 

LeetCode-922 Sort Array By Parity II Solution (with Java)

原文:https://www.cnblogs.com/sheepcore/p/12396178.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!