Skip to content

Instantly share code, notes, and snippets.

View zhangxiaomu01's full-sized avatar
🎯
Focusing

Jun Zhang zhangxiaomu01

🎯
Focusing
View GitHub Profile
class Solution {
public:
string longestPalindrome(string s) {
int start = 0, end = 0;
int len = 0;
for(int i = 0; i< s.size(); i++)
{
int len1 = PalindromeLength(s, i, i);
int len2 = PalindromeLength(s, i, i+1);
len = max(len1, len2);
class Solution {
public:
string longestPalindrome(string s) {
if(s == "")
return s;
int len = s.size();
int maxsLen = 0;
bool arr[len][len];
string finalString;
class Solution {
public:
string preProcess(string s)
{
int len = s.size();
string proStr = "^";
//string numberStr = "#";
//string dollarStr = "$";
for(int i = 0; i < len; i++)
class Solution {
public:
string convert(string s, int num) {
int len = s.size();
string finalStr;
if(num == 1||len<=1) return s;
int k = 2 * num - 2;
for(int i = 0; i< num; i++)
{
for(int j = 0; i + j<len; j = j + k)
class Solution {
public:
int myAtoi(string str) {
long temp = 0;
int i = 0, sign = 1;
while(str[i] == ' ')
{
i++;
}
class Solution {
public:
bool isMatch(string s, string p) {
if(p.empty()) return s.empty();
bool myFirst = !s.empty() && (s[0] == p[0] || p[0] == '.');
return myFirst&&isMatch(s.substr(1),p.substr(1));
}
};
class Solution {
public:
bool isMatch(string s, string p) {
if(p.empty()) return s.empty();
bool myFirst = !s.empty() && (s[0] == p[0] || p[0] == '.');
if(p.size()>=2 && p[1] == '*')
{
return myFirst&&isMatch(s.substr(1),p)||isMatch(s, p.substr(2));
}
else
class Solution {
public:
bool isMatch(string s, string p) {
int len_s = s.size(), len_p = p.size();
bool dp[len_s+1][len_p+1];
//Since the dp[len_s][len_p] means comparison of two empty string, which should be true.
dp[len_s][len_p] = true;
for(int i = len_s; i>= 0; i--){
for(int j = len_p; j>= 0; j--){
class Solution {
public:
bool isMatch(string s, string p) {
int len_s = s.size(), len_p = p.size();
//We only allocate 2 columns, which reduce the space complexity to linear.
bool dp[2][len_p+1];
//Since the dp[len_s%2][len_p] means comparison of two empty string, which should be true.
dp[len_s%2][len_p] = true;
for(int i = len_s; i>= 0; i--){
class Solution {
public:
int maxArea(vector<int>& height) {
int len = height.size();
int maxWater = 0;
for(int i = 0; i< len; i++){
for(int j = i+1; j< len; j++){
int lens_i = height[i]>height[j]? height[j] : height[i];
int width = j - i;