Java- Accepted Solution


  • 3
    S

    public class NumArray {
    List list = new ArrayList<Integer>();

    public NumArray(int[] nums) {
       //int[] num = new int[nums.length];
       if(nums.length == 0)
        return;
       list.add(0, nums[0]);
       for (int i=1; i<nums.length; i++){
           list.add(i, ((int)list.get(i-1) + nums[i]));
       }
    }
    
    
    public int sumRange(int i, int j) {
        if(i==0)
            return ((int)list.get(j));
        return ((int)list.get(j) - (int)list.get(i-1));
    }
    

    }


  • 0
    C

    What is the "return" in NumArray(int[] nums) mean? Exit function?


Log in to reply
 

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