C++ 424ms runtime


  • -1
    H
    class NumArray {
    private:
        vector<int> numberArray;
    public:
        NumArray(vector<int> &nums) {
            for(int i=0; i< nums.size(); i++){
                    numberArray.push_back(nums[i]);
                  // numberArray = nums;
            }
        }
    
        int sumRange(int i, int j) {
            int sum=0;
            for(int a= i; a<= j; a++){
                sum+= numberArray[a];
            }
            return sum;
        }
    };
    
    
    // Your NumArray object will be instantiated and called as such:
    // NumArray numArray(nums);
    // numArray.sumRange(0, 1);
    // numArray.sumRange(1, 2);

Log in to reply
 

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