Skip to content

Instantly share code, notes, and snippets.

class Solution {
public:
vector<int> eventualSafeNodes(vector<vector<int>>& graph) {
vector<State> states(graph.size(), UNKNOWN);
vector<int> ans;
for(int i = 0; i < graph.size(); i++) {
if (dfs(graph, i, states) == SAFE) {
ans.push_back(i);
}
}
class Solution {
public:
bool isBipartite(vector<vector<int>>& graph) {
int n = graph.size();
vector<int> colors(n, -1);
for(int i = 0; i < n; i++) {
if (colors[i] == -1) {
if (!BFS(graph, colors, 0, i)) {
return false;
}
class Solution {
private:
unordered_map<string, deque<string>> trips_;
vector<string> route_;
public:
vector<string> findItinerary(vector<pair<string, string>> tickets) {
route_.clear();
trips_.clear();
for(const auto& pair: tickets)
class Solution {
public:
vector<int> findRedundantConnection(vector<vector<int>>& edges) {
unordered_map<int, vector<int>> graph;
for(const auto& edge: edges) {
int u = edge[0];
int v = edge[1];
unordered_set<int> visited;
if (hashPath(u, v, graph, visited)) return edge;
graph[u].push_back(v);
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {