Skip to content

Instantly share code, notes, and snippets.

void mutate_binary_tree(const shared_ptr<BinaryTree> &root) {
if (!root) {
return;
}
mute_dfs_post_order(root);
shared_ptr<BinaryTree> n = root;
while (n->left) {
auto current = n;
auto next = current->left;
next = get_right_most(next);
void mutate_tree_bfs(const shared_ptr<BinaryTree> &root) {
stack<shared_ptr<BinaryTree>> stack1;
stack<shared_ptr<BinaryTree>> stack2;
stack<shared_ptr<BinaryTree>> *st1 = &stack1;
stack<shared_ptr<BinaryTree>> &st2 = &stack2;
st1->push(root);
shared_ptr<BinaryTree> *temp = nullptr;
bool is_left_most = true;
void encode_word(string &s) {
encode_word_helper(s, 0);
}
void encode_word_helper(string &s, int i) {
if (i == s.size()) {
cout << reduce(s) << endl;
return;
}
void permutation(string &s) {
permu_helper(s, 0);
}
void permu_helper(string &s, int level) {
if (level == s.size()) {
cout << s << endl;
return;
}
void reverse(stack<int> &st) {
if (!st.empty()) {
int temp = st.top();
st.pop();
reverse(st);
insert_botom(st, temp);
}
}
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) {
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;
}
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:
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 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;
}