303 Posted on 2026-01-12 Edited on 2026-01-13 In 解題紀錄 , LeetCode Views: 題目:https://leetcode.com/problems/range-sum-query-immutable/description/ 1234567891011121314151617181920212223#define MAXN 10005class NumArray {public: int prefix[MAXN] = {}; NumArray(vector<int>& nums) { prefix[0] = 0; for(int i = 1; i<=nums.size(); ++i){ prefix[i] = nums[i-1] + prefix[i-1]; } } int sumRange(int left, int right) { return prefix[right+1] - prefix[left]; }};/** * Your NumArray object will be instantiated and called as such: * NumArray* obj = new NumArray(nums); * int param_1 = obj->sumRange(left,right); */