File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed
src/main/java/g3401_3500/s3467_transform_array_by_parity Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change 1
1
package g3401_3500 .s3467_transform_array_by_parity ;
2
2
3
- // #Easy #2025_03_02_Time_2_ms_(100.00%)_Space_45.06_MB_(100.00%)
4
-
5
- import java .util .Arrays ;
3
+ // #Easy #2025_03_06_Time_1_ms_(100.00%)_Space_45.26_MB_(23.27%)
6
4
7
5
public class Solution {
8
6
public int [] transformArray (int [] nums ) {
9
- for (int i = 0 ; i < nums .length ; i ++) {
10
- if (nums [i ] % 2 == 0 ) {
11
- nums [i ] = 0 ;
12
- } else {
13
- nums [i ] = 1 ;
7
+ int size = nums .length ;
8
+ int [] ans = new int [size ];
9
+ int countEven = 0 ;
10
+ for (int num : nums ) {
11
+ if ((num & 1 ) == 0 ) {
12
+ countEven ++;
14
13
}
15
14
}
16
- Arrays .sort (nums );
17
- return nums ;
15
+ for (int i = countEven ; i < size ; i ++) {
16
+ ans [i ] = 1 ;
17
+ }
18
+ return ans ;
18
19
}
19
20
}
You can’t perform that action at this time.
0 commit comments