Skip to content

Commit

Permalink
Q2149 added.
Browse files Browse the repository at this point in the history
  • Loading branch information
isinsuarici committed Mar 3, 2023
1 parent eb38d90 commit 8d7a6f8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions M_2149_RearrangeArrayElementsbySign.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public int[] rearrangeArray(int[] nums) {
int ret[] = new int[nums.length];
int even=0;
int odd=1;
for(int i=0; i<nums.length;i++){
if(nums[i]>0){
ret[even]=nums[i];
even+=2;
}
else{
ret[odd]=nums[i];
odd+=2;
}
}
return ret;
}
}

0 comments on commit 8d7a6f8

Please sign in to comment.