C# - update array in place


  • 0
    public class NumArray 
    {
        int[] nums = null;
        public NumArray(int[] nums) 
        {
            this.nums = nums;
            for (int i = 1; i < nums.Length; i++)
            {
                nums[i] += nums[i-1];
            }
        }
    
        public int SumRange(int i, int j) 
        {
            return this.nums[j] - (i == 0 ? 0 : this.nums[i - 1]);
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.