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
void print_depth_first_traversal(GraphNode *node) { | |
if (is_visited(node)) { | |
return; | |
} | |
mark_visited(node); | |
for (GraphNode *neighbor : node->neighbors) { | |
print_depth_first_traversal(neighbor); | |
} |
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
int fun(int n) { | |
// ... | |
return fun(n-1); | |
} |
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
int factorial_1() { | |
return 1; | |
} | |
int factorial_2() { | |
int fact_1 = factorial_1(); | |
return 2 * fact_1; | |
} | |
int factorial_3() { |
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
int factorial(int n) { | |
if (n == 1) { | |
return 1; | |
} | |
int fact_n_1 = factorial(n-1); | |
return n * fact_n_1; | |
} |
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
int fun2(int x) { | |
// .... | |
fun1(x-1); | |
// .... | |
} |
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
int fun1(int x) { | |
// .... | |
fun2(x-1); | |
// .... | |
} |
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: | |
map<char, string> numToString = {{'2', "abc"}, {'3', "def"}, {'4', "ghi"}, | |
{'5', "jkl"}, {'6', "mno"}, {'7', "pqrs"}, | |
{'8', "tuv"}, {'9', "wxyz"}}; | |
vector<string> answer; | |
string input; | |
void recurse(string path, int index) { | |
if (!(index < input.length())) { // the entire string is processed already. |
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 { | |
char openingParenthesis = '('; | |
char closingParenthesis = ')'; | |
vector<string> answer; | |
void recurse(string &path, int unusedOpen, int unusedClose) { | |
if (unusedOpen < 0 || unusedClose < 0) { // invalid state. | |
return; | |
} | |
if (unusedOpen > unusedClose) { // path is not well-formed. |
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>> answer; | |
vector<int> numbers; | |
void recurse(vector<int> &path, int index, int target) { | |
if (target == 0) { // no more numbers are required. | |
answer.push_back(path); // add current numbers into the answer. | |
return; | |
} |
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>> answer; | |
vector<int> numbers; | |
void recurse(vector<int> &path, int startIndex, int target) { | |
if (target == 0) { // no more numbers are required. | |
answer.push_back(path); // add current numbers into the answer. | |
return; | |
} |