We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bc120fc commit 589c092Copy full SHA for 589c092
scripts/algorithms/S/Sort Array By Parity/Sort Array By Parity.rs
@@ -0,0 +1,20 @@
1
+// Runtime: 0 ms (Top 100.0%) | Memory: 2.20 MB (Top 28.33%)
2
+
3
+impl Solution {
4
+ pub fn sort_array_by_parity(nums: Vec<i32>) -> Vec<i32> {
5
+ let mut even = Vec::new();
6
+ let mut odd = Vec::new();
7
8
+ for num in nums {
9
+ if num % 2 == 0 {
10
+ even.push(num);
11
+ } else {
12
+ odd.push(num);
13
+ }
14
15
16
+ even.extend(odd);
17
+ even
18
19
+}
20
0 commit comments