Shawn's Blog

  • Home
  • Tags
  • Categories
  • Archives
  • Search
  • Table of Contents
  • Overview

Shawn

若有恒,何必三更眠五更起;最无益,莫过一日曝十日寒。
392 posts
13 categories
114 tags

LeetCode 303. Range Sum Query - Immutable

Posted on 2021-03-01 Edited on 2024-11-24 In LeetCode
1
2
3
4
5
6
7
8
9
10
11
12
13
class 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];
}
};
# Dynamic Programming
LeetCode 896. Monotonic Array
LeetCode 304. Range Sum Query 2D - Immutable
© 2024 Shawn
Powered by Hexo & NexT.Mist
0%