Simple Solution - Java


  • 0
    H
    public class NumArray {
        private int[] nums;
        
        public NumArray(int[] nums) {
            this.nums = nums;
        }
        public int sumRange(int i, int j) {
            int sum = 0;
            for (int index = i; index <= j; index++){
                sum += nums[index];
            }
            return sum;
        }
    }

Log in to reply
 

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