leetcode

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

commita4d87fe1697deeec15446391bafcfd89aa6ded01
parent4028c7c448da955a7cf3cd52d316deecc72a1a73
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateSat, 7 Sep 2024 13:20:17 +0200

1 Random Problem

Diffstat:
AProblems/2059.cpp|++++++++++++++++++++++++++++++++++++++++++
MREADME.md|+

2 files changed, 43 insertions(+), 0 deletions(-)


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

@@ -0,0 +1,42 @@

class Solution {
public:
int minimumOperations(const vector<int> &nums, int start, int goal) const {
bool seen[1001] = {0};
queue<int> q;
seen[start] = true;
q.emplace(start);
for (int lvl = 1; !q.empty(); lvl++) {
for (int l = size(q); l > 0; l--) {
const int crnt = q.front();
q.pop();
for (const int n : nums) {
const int x = crnt ^ n;
if (x == goal) return lvl;
if (x >= 0 && x <= 1000 && !seen[x]) {
seen[x] = true;
q.emplace(x);
}
const int y = crnt + n;
if (y == goal) return lvl;
if (y >= 0 && y <= 1000 && !seen[y]) {
seen[y] = true;
q.emplace(y);
}
const int z = crnt - n;
if (z == goal) return lvl;
if (z >= 0 && z <= 1000 && !seen[z]) {
seen[z] = true;
q.emplace(z);
}
}
}
}
return -1;
}
};

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

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

| 2050 | Hard | [Parallel Courses III](Problems/2050.cpp) |
| 2053 | Easy | [Kth Distinct String in an Array](Problems/2053.cpp) |
| 2058 | Medium | [Find the Minimum and Maximum Number of Nodes Between Critical Points](Problems/2058.cpp) |
| 2059 | Medium | [Minimum Operations to Convert Number](Problems/2059.cpp) |
| 2063 | Medium | [Vowels of All Substrings](Problems/2063.cpp) |
| 2064 | Medium | [Minimized Maximum of Products Distributed to Any Store](Problems/2064.cpp) |
| 2070 | Medium | [Most Beautiful Item for Each Query](Problems/2070.cpp) |