LeetCode 303. Range Sum Query - Immutable Posted on 2021-03-01 Edited on 2024-11-24 In LeetCode 12345678910111213class NumArray {private: vector<int> sums;public: NumArray(vector<int>& nums) { int sum = 0; for (int num : nums) sums.emplace_back(sum += num); } int sumRange(int i, int j) { return i == 0 ? sums[j] : sums[j] - sums[i - 1]; }};