Run-length decode
Java
Hard
4 views
Problem Description
Task: decode pairs (value,count) into an array.
Output Format
Return value
Constraints
Total length can be computed first.
Official Solution
static int[] decode(int[][] pairs){int total=0;for(int[] p:pairs) total+=p[1];int[] a=new int[total];int k=0;for(int[] p:pairs){for(int i=0;i<p[1];i++) a[k++]=p[0];}return a;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!