Rearrange array by sign (stable)
Java
Hard
5 views
Problem Description
Task: place negative numbers first then non-negative, keeping relative order inside each group.
Output Format
Return value
Constraints
Use extra array.
Official Solution
static int[] stablePartitionSign(int[] a){int n=a.length;int[] r=new int[n];int k=0;for(int x:a) if(x<0) r[k++]=x;for(int x:a) if(x>=0) r[k++]=x;return r;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!