leetcode[Range Sum Query - Immutable]待整理多种解法

xiaoxiao2021-02-27  115

public class NumArray { int[] nums = null; public NumArray(int[] nums) { this.nums = nums; } public int sumRange(int i, int j) { if(i < 0 || j >= nums.length){ return 0; } else{ int sum = 0; for(int k = i; k <= j; k++){ sum += nums[k]; } return sum; } } } /** * Your NumArray object will be instantiated and called as such: * NumArray obj = new NumArray(nums); * int param_1 = obj.sumRange(i,j); */
转载请注明原文地址: https://www.6miu.com/read-16036.html

最新回复(0)