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
/* | |
Given n, generate all structurally unique BST's (binary search trees) that | |
store values 1...n. | |
For example, | |
Given n = 3, your program should return all 5 unique BST's shown below. | |
1 3 3 2 1 | |
\ / / / \ \ | |
3 2 1 1 3 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
class Solution { | |
public: | |
bool dfs(const string &s1, int i, const string &s2, int j, const string&s3, int k, vector<vector<int> > &dp) { | |
if(i == s1.size() && j == s2.size() && k == s3.size()) { | |
return true; | |
} | |
if(i == s1.size()) { | |
return s2.substr(j) == s3.substr(k); | |
} |
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
/* | |
Given a collection of intervals, merge all overlapping intervals. | |
For example, | |
Given [1,3],[2,6],[8,10],[15,18], | |
return [1,6],[8,10],[15,18]. | |
*/ | |
/** | |
* Definition for an interval. |
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
/* | |
Given a m x n grid filled with non-negative numbers, | |
find a path from top left to bottom right which minimizes | |
the sum of all numbers along its path. | |
Note: You can only move either down or right at any point in time. | |
*/ | |
class Solution { | |
public: |
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
/* | |
Symmetric Tree | |
Given a binary tree, check whether it is a mirror of itself | |
(ie, symmetric around its center). | |
For example, this binary tree is symmetric: | |
1 | |
/ \ | |
2 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
/* | |
Given a 2D board and a word, find if the word exists in the grid. | |
The word can be constructed from letters of sequentially | |
cell, where "adjacent" cells are those horizontally or vertically | |
neighboring. The same letter cell may not be used more than once. | |
For example, | |
Given board = |
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
/* | |
Given a sorted array and a target value, return the index if the target is found. | |
If not, return the index where it would be if it were inserted in order. | |
You may assume no duplicates in the array. | |
Here are few examples. | |
[1,3,5,6], 5 → 2 | |
[1,3,5,6], 2 → 1 | |
[1,3,5,6], 7 → 4 |
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
/* | |
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like | |
this: (you may want to display this pattern in a fixed font for better legibility) | |
P A H N | |
A P L S I I G | |
Y I R | |
And then read line by line: "PAHNAPLSIIGYIR" | |
Write the code that will take a string and make this conversion given a number of rows: |
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
/* | |
Unique Binary Search Trees | |
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? | |
For example, | |
Given n = 3, there are a total of 5 unique BST's. | |
1 3 3 2 1 | |
\ / / / \ \ | |
3 2 1 1 3 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
#include <iostream> | |
using namespace std; | |
/* | |
###################################################################################################### | |
###################################################################################################### | |
1 | |
*/ |
NewerOlder