This file contains hidden or 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: | |
struct Node { | |
Node(): left(nullptr), right(nullptr) {} | |
shared_ptr<Node> left, right; | |
}; | |
typedef shared_ptr<Node> NodePtr; | |
shared_ptr<Node> root; |
This file contains hidden or 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; | |
class SquareFreeString { | |
public: | |
string isSquareFree(string s) { | |
if (s.length() < 2) | |
return "square-free"; | |
for (int l = 2; l <= s.length(); l += 2) { | |
for (int shift = 0; shift < s.length() - l + 1; ++shift) { |
This file contains hidden or 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 <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
#include <queue> | |
#include <list> | |
#include <bitset> | |
using namespace std; |
This file contains hidden or 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; | |
// Assume that you have N sticks with different lengths | |
// You can connect these sticks to get a composed stick of some length | |
// You are given a targetLenth, is it possible to get a composed stick of this length? | |
// For this solution I represent problem a s graph where a vertex is marked by the mask (every bit says which of the sticks | |
// we have already chosen) and the length of edges are the length of the corresponding sticks. | |
// For instance, if we have lengths=[2,3,5], than 0th vertex corresponds to the case when we haven't picked up a stick yet, |
This file contains hidden or 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
/** | |
* Definition for an interval. | |
* struct Interval { | |
* int start; | |
* int end; | |
* Interval() : start(0), end(0) {} | |
* Interval(int s, int e) : start(s), end(e) {} | |
* }; | |
*/ | |
class SummaryRanges { |
This file contains hidden or 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 <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
typedef vector<int>::iterator Iterator; | |
void merge_sort(Iterator b, Iterator e) { | |
if (e - b <= 1) return; | |
auto m = b + (e - b)/2; |
This file contains hidden or 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
// Solution for grafixMask from TC SRM211 | |
#include <bits/stdc++.h> | |
using namespace std; | |
// using DFS approach | |
class grafixMask | |
{ | |
public: | |
vector<int> sortedAreas(vector <string> rectangles) | |
{ |
This file contains hidden or 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; | |
struct Road { | |
string id; | |
int x,y; | |
int cost; | |
Road(string a, int b, int c, int d) : id(a), x(b), y(c), cost(d) {} | |
}; |
This file contains hidden or 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; | |
int main(int, char**) | |
{ | |
int n,m; | |
cin >> n >> m; | |
vector<vector<int>> matrix(n, vector<int>(m,0)); | |
for(int i = 0; i < n; ++i) { | |
for (int j = 0; j < m; ++j) { |
This file contains hidden or 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; | |
void dfs(vector<int>& colors, vector< list<int> >& adjlist, int cur, int parent) { | |
int c = 1; | |
for (int a : adjlist[cur]) { | |
if (a != parent) { | |
while (c == colors[cur] || c == colors[parent]) | |
++c; | |
colors[a] = c; |
OlderNewer