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: | |
bool makesquare(vector<int>& nums) { | |
if (nums.empty() || nums.size() < 4) return false; | |
int sum = accumulate(nums.begin(), nums.end(), 0); | |
if (sum % 4 != 0) return false; | |
int n = nums.size(), all = (1 << n) - 1, target = sum/4; | |
vector<int> masks, validHalf(1<<n, false); | |
for(int i = 0; i < all; i++) { | |
int curSum = 0; |
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<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); |
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
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; |
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: | |
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; | |
} |
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<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)); | |
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<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, |
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
/* | |
// 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 |
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
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(); |
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) { | |
// 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 |
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<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; |