leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE |

commit38fecc903b4a014cd562d14184b5c0f8770374af
parentf1b10a603adde3e7158265b46ca5c38851e2c2c1
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateFri, 5 Jan 2024 17:26:54 +0000

1 Random Problem

Diffstat:
MProblems/1695.cpp|+++++++++++++-------
MREADME.md|+

2 files changed, 14 insertions(+), 7 deletions(-)


diff --git a/Problems/1695.cpp b/Problems/1695.cpp

@@ -1,12 +1,18 @@

class Solution {
public:
vector<int> getSumAbsoluteDifferences(vector<int> &nums) {
const int n = nums.size();
int left = 0, right = accumulate(begin(nums), end(nums), 0);
for (int i = 0; i < n; ++i) {
right -= nums[i], left += nums[i];
nums[i] = right - left + (2 * i - n + 2) * nums[i];
int maximumUniqueSubarray(const vector<int> &nums) const {
static bool seen[10001];
memset(seen, 0x00, sizeof(seen));
int res = 0, sum = 0, i = 0;
for (int j = 0; j < nums.size(); j++) {
while (seen[nums[j]]) {
seen[nums[i]] = 0;
sum -= nums[i++];
}
seen[nums[j]] = 1;
sum += nums[j];
res = max(res, sum);
}
return nums;
return res;
}
};

diff --git a/README.md b/README.md

@@ -805,6 +805,7 @@ for solving problems.

| 1688 | Easy | [Count of Matches in Tournament](Problems/1688.cpp) |
| 1689 | Medium | [Partitioning Into Minimum Number Of Deci-Binary Numbers](Problems/1689.cpp) |
| 1693 | Easy | [Daily Leads and Partners](Problems/1693.cpp) |
| 1695 | Medium | [Maximum Erasure Value](Problems/1695.cpp) |
| 1696 | Medium | [Jump Game VI](Problems/1696.cpp) |
| 1697 | Hard | [Checking Existence of Edge Length Limited Paths](Problems/1697.cpp) |
| 1700 | Easy | [Number of Students Unable to Eat Lunch](Problems/1700.cpp) |