leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | 137f3d4b6631ffc3cb3abc47ae2cf2e6da8791e1 |
parent | b723eb133dfb085cc2894fbd35e92857bb2c90d1 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Tue, 15 Oct 2024 13:44:39 +0200 |
1 Random Problem
Diffstat:A | Problems/0303.cpp | | | ++++++++++++ |
M | README.md | | | + |
2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/Problems/0303.cpp b/Problems/0303.cpp
@@ -0,0 +1,12 @@
class NumArray {
vector<int> prefix;
public:
NumArray(const vector<int> &nums) : prefix(size(nums) + 1) {
for (int i = 0, acc = 0; i < size(nums); i++) {
prefix[i + 1] = acc += nums[i];
}
}
int sumRange(int left, int right) const { return prefix[right + 1] - prefix[left]; }
};
diff --git a/README.md b/README.md
@@ -267,6 +267,7 @@ for solving problems.
| 0297 | Hard | [Serialize and Deserialize Binary Tree](Problems/0297.cpp) |
| 0299 | Medium | [Bulls and Cows](Problems/0299.cpp) |
| 0300 | Medium | [Longest Increasing Subsequence](Problems/0300.cpp) |
| 0303 | Easy | [Range Sum Query - Immutable](Problems/0303.cpp) |
| 0304 | Medium | [Range Sum Query 2D - Immutable](Problems/0304.cpp) |
| 0306 | Medium | [Additive Number](Problems/0306.cpp) |
| 0309 | Medium | [Best Time to Buy and Sell Stock with Cooldown](Problems/0309.cpp) |