Monday, February 15, 2021

Leetcode Everyday: 1313. Decompress Run-Length Encoded List. Easy

public class Solution {
    public int[] DecompressRLElist(int[] nums) {
        var list = new List<int>();
        for (var i = 0; i < nums.Length; i += 2) {
            var count = nums[i];
            var toDup = nums[i + 1];
            
            while (count-- > 0) {
                list.Add(toDup);
            }
        }
        return list.ToArray();
    }
}
Source: https://leetcode.com/problems/decompress-run-length-encoded-list/

No comments:

Post a Comment