publicvoidupdate(int index, int val) { intincreaseNum= val - nums[index]; nums[index] = val; for (inti= index + 1; i < sums.length; i += lowBit(i)) { sums[i] += increaseNum; } }
privateintquerySum(int index) { intsum=0; for (inti= index; i > 0; i -= lowBit(i)) { sum += sums[i]; }
return sum; }
privateintlowBit(int n) { return n & (-n); } } /** * Your NumArray object will be instantiated and called as such: * NumArray obj = new NumArray(nums); * obj.update(index,val); * int param_2 = obj.sumRange(left,right); */