leetcode

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

commit9a21df3f3c06fa914265571633c3fb5407bbe8f4
parent0ff3eded1ba66f25ed63019c11c4c39db6b561cb
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateFri, 6 Oct 2023 16:46:33 +0000

Daily Problem and 1 Random Problem

Diffstat:
MProblems/0343.cpp|+++++++++++++++++++---------
AProblems/2683.cpp|++++++
MREADME.md|+

3 files changed, 26 insertions(+), 9 deletions(-)


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

@@ -1,13 +1,23 @@

// DP
class Solution {
public:
int integerBreak(int n) {
if (n == 2) return 1;
if (n == 3) return 2;
static int dp[64];
if (n % 3 == 0)
return pow(3, n / 3);
else if (n % 3 == 1)
return pow(3, n / 3 - 1) * 4;
return pow(3, n / 3) * (n % 3);
int rec(const int n) const {
if (n <= 3) return n;
if (dp[n] != -1) return dp[n];
int res = n;
for (int i = 2; i < n; i++)
res = max(res, i * rec(n - i));
return dp[n] = res;
}
public:
Solution() { memset(dp, 0xFF, sizeof(dp)); }
int integerBreak(const int n) const {
if (n <= 3) return n - 1;
return rec(n);
;
}
};
int Solution::dp[64];

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

@@ -0,0 +1,6 @@

class Solution {
public:
bool doesValidArrayExist(const vector<int> &derived) const {
return accumulate(begin(derived), end(derived), 0, bit_xor<int>()) == 0;
}
};

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

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

| 2666 | Easy | [Allow One Function Call](Problems/2666.js) |
| 2667 | Easy | [Create Hello World Function](Problems/2667.js) |
| 2676 | Medium | [Throttle](Problems/2676.js) |
| 2683 | Medium | [Neighboring Bitwise XOR](Problems/2683.cpp) |
| 2685 | Medium | [Count the Number of Complete Components](Problems/2685.cpp) |
| 2707 | Medium | [Extra Characters in a String](Problems/2707.cpp) |
| 2711 | Medium | [Difference of Number of Distinct Values on Diagonals](Problems/2711.cpp) |