leetcode

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

commitd8faf52829a7587344fa53464d9938ab3fc423cf
parent3ee55c0e521bc706d1d73d229c343f79e2936bd3
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateWed, 9 Oct 2024 18:03:49 +0200

1 Random Problem

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

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


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

@@ -0,0 +1,50 @@

static const auto _ = [] {
ios::sync_with_stdio(0);
cin.tie(0);
return 0;
}();
class Solution {
public:
vector<int> remainingMethods(int n, int k, const vector<vector<int>> &invocations) const {
static bool seen[100001];
vector<vector<int>> invoke(n);
memset(seen, 0x00, sizeof(seen));
for (const auto &in : invocations) {
invoke[in[0]].push_back(in[1]);
}
queue<int> q;
q.emplace(k);
seen[k] = true;
while (!q.empty()) {
const int root = q.front();
q.pop();
for (const auto next : invoke[root]) {
if (seen[next]) continue;
seen[next] = true;
q.emplace(next);
}
}
for (int i = 0; i < n; i++) {
if (seen[i]) continue;
for (const auto in : invoke[i]) {
if (seen[in]) {
vector<int> res(n);
iota(begin(res), end(res), 0);
return res;
}
}
}
vector<int> res;
for (int i = 0; i < n; i++) {
if (seen[i]) continue;
res.emplace_back(i);
}
return res;
}
};

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

@@ -1375,3 +1375,4 @@ for solving problems.

| 3239 | Medium | [Minimum Number of Flips to Make Binary Grid Palindromic I](Problems/3239.cpp) |
| 3249 | Medium | [Count the Number of Good Nodes](Problems/3249.cpp) |
| 3254 | Medium | [Find the Power of K-Size Subarrays I](Problems/3254.cpp) |
| 3310 | Medium | [Remove Methods From Project](Problems/3310.cpp) |