leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | 69adffa2824c91f6bf332c6c3150941436d877fa |
parent | 2a72d609a5082614d3e554ea5d4fbc0d27d647e7 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Tue, 17 Sep 2024 21:23:42 +0200 |
1 Random Problem
Diffstat:M | Problems/1262.cpp | | | ++++--- |
M | README.md | | | + |
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/Problems/1262.cpp b/Problems/1262.cpp
@@ -1,11 +1,12 @@
class Solution {
public:
int maxSumDivThree(const vector<int> &nums) const {
vector<int> dp(3, 0);
int dp[3] = {0}, prev[3];
for (const int n : nums) {
for (const int m : vector<int>(dp)) {
dp[(m + n) % 3] = max(dp[(m + n) % 3], m + n);
memcpy(prev, dp, 3 * sizeof(int));
for (const int prev : span(prev, 3)) {
dp[(prev + n) % 3] = max(dp[(prev + n) % 3], prev + n);
}
}
diff --git a/README.md b/README.md
@@ -740,6 +740,7 @@ for solving problems.
| 1255 | Hard | [Maximum Score Words Formed by Letters](Problems/1255.cpp) |
| 1261 | Medium | [Find Elements in a Contaminated Binary Tree](Problems/1261.cpp) |
| 1262 | Medium | [Greatest Sum Divisible by Three](Problems/1262.cpp) |
| 1262 | Medium | [Greatest Sum Divisible by Three](Problems/1262.cpp) |
| 1266 | Easy | [Minimum Time Visiting All Points](Problems/1266.cpp) |
| 1267 | Medium | [Count Servers that Communicate](Problems/1267.cpp) |
| 1268 | Medium | [Search Suggestions System](Problems/1268.cpp) |