Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions leetcode2/1easy/이준열/2511.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
class Solution {
public:
int captureForts(vector<int>& forts) {
int output = 0;

for (int i = 0; i < forts.size(); i++)
{
if (forts[i] == 1)
{
int left = i - 1;
int right = i + 1;

int leftCnt = 0;
int rightCnt = 0;

int maxLeft = 0;
int maxRight = 0;

bool metEmptyLeft = false; // meeting -1, 1 or end is wrong
bool metEmptyRight = false;

while (left >= 0)
{
if (forts[left] == 0)
{
leftCnt++;
}
else if (forts[left] == 1)
{
break;
}
else
{
maxLeft = max(maxLeft, leftCnt);
metEmptyLeft = true;
break;
}
left--;
}
if (metEmptyLeft)
output = max(output, maxLeft);
while (right <= forts.size()-1)
{
if (forts[right] == 0)
{
rightCnt++;
}
else if (forts[right] == 1)
{
break;
}
else
{
maxRight = max(maxRight, rightCnt);
metEmptyRight = true;
break;
}
right++;
}
if (metEmptyRight)
output = max(output, maxRight);
}
}

return output;
}
};
44 changes: 44 additions & 0 deletions leetcode2/2medium/이준열/3310.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class Solution {
public:
unordered_set<int> sus;
map<int, vector<int> > graph;
map<int, vector<int> > reverseGraph;

void dfs(int target)
{
if (sus.count(target)) return;
sus.insert(target);
for (int n: graph[target]) dfs(n);
}

vector<int> remainingMethods(int n, int k, vector<vector<int>>& invocations) {

for (vector<int> v: invocations)
{
graph[v[0]].push_back(v[1]);
reverseGraph[v[1]].push_back(v[0]);
}

dfs(k);

for (int i : sus)
{
for (int rev: reverseGraph[i])
{
if (!sus.count(rev))
{
vector<int> all(n);
iota(all.begin(), all.end(), 0);
return all;
}
}
}

vector<int> output;
for (int j = 0; j < n; j++)
{
if (!sus.count(j)) output.push_back(j);
}
return output;
}
};