LeetCode_Study_Plan/Programming Skills

303. Range Sum Query - Immutable java

개발하는루루 2022. 9. 25. 15:22

https://leetcode.com/problems/range-sum-query-immutable/?envType=study-plan&id=programming-skills-i 

 

Range Sum Query - Immutable - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

class NumArray {
    int[] nums;

    public NumArray(int[] nums) {
        this.nums = nums;
    }

    public int sumRange(int left, int right) {
        int sum = 0;
        for(int i = left; i <= right; i++){
            sum += this.nums[i];
        }
        return sum;
    }
}