Skip to content

Instantly share code, notes, and snippets.

class Solution {
public:
vector<string> wordBreak(string s, unordered_set<string> &dict) {
vector<vector<int> > path(s.size(), vector<int>());
vector<string> result;
vector<bool> word_map(s.size() + 1, false);
word_map[0] = true;
if (!s.size()) {
return result;
class Solution {
public:
double findMedianSortedArrays(int A[], int m, int B[], int n) {
int size = m + n;
if (size & 1) {
return find_kth((size >> 1) + 1, A, 0, m - 1, B, 0, n - 1);
} else {
return (find_kth(size >> 1, A, 0, m - 1, B, 0, n - 1) + find_kth((size >> 1) + 1, A, 0, m - 1, B, 0, n - 1)) / 2.0;
}
class Solution {
public:
bool isInterleave(string s1, string s2, string s3) {
if (!s1.size() && !s2.size() && !s3.size()) {
return true;
} else if (s1.size() > 0 && s2.size() > 0 && s3.size() > 0) {
vector<vector<vector<int>>> mmap(s1.size(), vector<vector<int>>(s2.size(), vector<int>(s3.size(), -1)));
return isInterleave(s1, s1.size() - 1, s2, s2.size() - 1, s3, s3.size() - 1, mmap);
} else {
return false;
class Solution {
public:
int numDistinct(string S, string T) {
int **mmap = (int **) malloc((S.size() + 1) * sizeof(int *));
for (int i = 0; i < S.size() + 1; ++i) {
mmap[i] = (int *) malloc((T.size() + 1) * sizeof(int));
}
for (int i = 0; i < S.size() + 1; ++i) {
mmap[i][0] = 1;
}
class Solution {
public:
int numDistinct(string S, string T) {
return numDistinct(S, T, 0, 0);
}
int numDistinct(string S, string T, int s, int t) {
if (t == T.size()) {
return 1;
}
class Solution {
public:
int minCut(string s) {
vector<vector<int>> p_map;
vector<int> c_map;
for (int i = 0; i < s.size(); i++) {
p_map.push_back(vector<int>(s.size(), -1));
c_map.push_back(-1);
}
for (int i = 0; i < s.size(); i++) {
class Solution {
public:
vector<string> letterCombinations(string digits) {
vector<string> mmap({"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"});
string buf;
vector<string> result;
dfs(0, mmap, buf, digits, result);
return result;
}
void print_external_nodes(shared_ptr<BinaryTree> root) {
if (!root) {
return;
}
left_dfs(root->left, true);
right_dfs(root->right, true);
}
void left_dfs(shared_ptr<BinaryTree> n, bool is_ext) {
void reverse(stack<int> &st) {
if (!st.empty()) {
int temp = st.top();
st.pop();
reverse(st);
insert_botom(st, temp);
}
}
void permutation(string &s) {
permu_helper(s, 0);
}
void permu_helper(string &s, int level) {
if (level == s.size()) {
cout << s << endl;
return;
}