This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
vector<int> findOrder(int numCourses, vector<vector<int>>& prerequisites) { | |
vector<vector<int>> adj(numCourses); | |
vector<int> indegree(numCourses,0),ans; | |
for(auto i:prerequisites) { | |
adj[i[1]].push_back(i[0]); | |
indegree[i[0]]++; | |
} | |
queue<int> q; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int networkDelayTime(vector<vector<int>>& times, int N, int K) { | |
const int E=times.size(); | |
int time=-1; | |
vector<pair<int,int>> adj[N+1]; | |
for(int i=0;i<E;i++){ | |
adj[times[i][0]].push_back(make_pair(times[i][1],times[i][2])); | |
} | |
vector<int> d(N+1,1<<30); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include < bits/stdc++.h > | |
using namespace std; | |
const int N = 2e5 + 1; | |
bool check(int x, int cur) | |
{ | |
int ans = 0; | |
for(int i = 1; i <= n; i++) | |
{ | |
if(!cur) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
#include<iostream> | |
using namespace std; | |
#define ll long long | |
int main() | |
{ | |
ios_base::sync_with_stdio(false); | |
cin.tie(NULL); | |
cout.tie(NULL); | |
int n; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
static bool comparator(vector<int>& a,vector<int>& b) | |
{ | |
return a[1]-a[0] > b[1]-b[0]; | |
} | |
public: | |
int twoCitySchedCost(vector<vector<int>>& costs) { | |
int n = costs.size(); | |
sort(costs.begin(),costs.end(),comparator); |