Skip to content

Instantly share code, notes, and snippets.

class Solution {
public:
vector<vector<string>> accountsMerge(vector<vector<string>>& accounts) {
vector<vector<string>> res;
int n = accounts.size();
unordered_map<string, vector<int>> m;
vector<int> visited(n, 0);
for(int i = 0; i < n; i++) {
for(int j = 1; j < accounts[i].size(); j++) {
m[accounts[i][j]].push_back(i);
package com.ck.fastq.util;
/**
* Created by s4553711 on 2018/5/31.
*/
public class FastqReader {
private StdinIterator reader;
private int head = 0;
private int mark = 0;
private int tail = 0;
class Solution {
public:
bool canVisitAllRooms(vector<vector<int>>& rooms) {
int numrooms = rooms.size();
vector<bool> visited(numrooms, false);
bool res = false;
visited = dfs(rooms, 0, visited);
for(int i = 0; i < numrooms; i++) {
if (!visited[i]) return false;
}
class Solution {
public:
vector<vector<bool>> visited;
int n, m;
vector<vector<char>> updateBoard(vector<vector<char>>& board, vector<int>& click) {
int x, y;
n = board.size();
m = board[0].size();
visited.assign(n, vector<bool>(m, false));
class Solution {
public:
vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int newColor) {
if (image[sr][sc] == newColor) return image;
int m = image.size();
int n = image[0].size();
floodFill(image, sc, sr, n, m, image[sr][sc], newColor);
return image;
}
void floodFill(vector<vector<int>>& image,
/*
// Employee info
class Employee {
public:
// It's the unique ID of each node.
// unique id of this employee
int id;
// the importance value of this employee
int importance;
// the id of direct subordinates
public void consume_iterator() {
FastqQueueReader<N> reader = new FastqQueueReader(broker);
int i = 0;
long prev = System.currentTimeMillis();
double accum = 0;
while(broker.isRunning() || reader.hasNext()) {
N data = reader.read();
accum += (((byte[])data).length*1.0d/(1024.0*1024.0));
if (i % 40000 == 0) {
long now_st = System.currentTimeMillis();
class Solution {
public:
int networkDelayTime(vector<vector<int>>& times, int N, int K) {
// first v, second w
vector<vector<pair<int, int> > > adj(N+1, vector<pair<int, int> >());
// dist and parent
vector<pair<int, int> > dist_p(N+1, make_pair(INT_MAX, -1));
// visited
vector<bool > visited(N+1, false);
// initialize
class Solution {
public:
vector<double> calcEquation(vector<pair<string, string>> equations, vector<double>& values, vector<pair<string, string>> queries) {
unordered_map<string, unordered_map<string, double>> g;
for(int i = 0; i < equations.size(); i++) {
const string& A = equations[i].first;
const string& B = equations[i].second;
const double k = values[i];
g[A][B] = k;
g[B][A] = 1.0 / k;
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);
}
}