Time limit exceed

  • 0

    Here is my solution for the Range Sum Query problem, I thought it is efficient, but I got time limit exceed, Could anyone tell me how I can do better? I appreciate it.
    public class NumArray {

    private int[] Nums; 
    public NumArray(int[] nums) {
        Nums = nums;
    public int sumRange(int i, int j) {
        int Sum = 0;
        if(i == j){
            Sum = Nums[j];
            Sum = Nums[i] + sumRange(i+1,j);
        return Sum;


Log in to reply

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