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: | |
int removeDuplicates(int A[], int n) { | |
int index = 0; | |
bool twice = false; | |
if(n == 0) return 0; | |
for(int i = 1; i < n; i++) | |
if(A[index] != A[i]){ | |
index ++; |
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: | |
bool check(char *a,char *b, int len){ | |
for(int i = 0; i < len; i++) | |
if(*(a+i) != *(b+i)) | |
return false; | |
return true; | |
} | |
char *strStr(char *haystack, char *needle) { | |
int lenH = strlen(haystack); |
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: | |
int removeDuplicates(int A[], int n) { | |
int p1 = 0; | |
int last = A[p1]; | |
if(n == 0) return 0; | |
if(n == 1) return 1; | |
for(int p2 = 1; p2 < n; p2++){ |
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: | |
int minCut(string s) { | |
int n = s.size(); | |
bool isPal[n][n]; | |
int m[n + 1]; | |
for(int i = 0; i <= n; i++) | |
m[i] = n - i - 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: | |
vector<vector<string>> partition(string s) { | |
int n = s.size(); | |
vector<vector<string>> result; | |
vector<string> path; | |
vector<vector<bool>> isPal(n, vector<bool>(n, false)); | |
for(int i = n - 1; i >= 0; i--) | |
for(int j = i; j < n; j++) |
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: | |
bool isInterleave(string s1, string s2, string s3) { | |
int len1 = s1.size(), len2 = s2.size(), len3 = s3.size(); | |
if(len1 + len2 != len3) | |
return false; | |
bool dp[len1 + 1][len2 + 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: | |
string longestPalindrome(string s) { | |
int n = s.size(); | |
int start = 0, Max = 0; | |
bool dp[n][n]; | |
for(int i = n - 1; i >= 0; i--) | |
for(int j = i; j < n; j++){ | |
dp[i][j] = ( s[i]==s[j] && ((j - i < 2) || dp[i+1][j-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: | |
int minPathSum(vector<vector<int> > &grid) { | |
int column = grid[0].size(); | |
int row = grid.size(); | |
int dp[column]; | |
memset(dp, 0, sizeof(dp)); | |
for(int i = 0; i < row; i++){ |
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: | |
int numTrees(int n) { | |
int dp[n+1];// index from 0 to n | |
memset(dp, 0, sizeof(dp));// you have to initialize to make sure the initial values | |
dp[0] = 1; | |
for(int i = 1; i <= n; i++) | |
for(int j = 0; j < i; j++) |
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: | |
void merge(int A[], int m, int B[], int n) { | |
int lastPos = m + n - 1; | |
int flagA = m - 1, flagB = n - 1; | |
while(lastPos >= 0){ | |
if(flagB < 0 || (flagA >= 0 && A[flagA] >= B[flagB])){ | |
A[lastPos] = A[flagA]; | |
flagA --; |
NewerOlder