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
struct Entry { | |
int val; | |
int index; | |
Entry(int v, int i): val(v), index(i) {} | |
}; | |
static bool isLess(const Entry a, const Entry b) { | |
return a.val < b.val; | |
} |
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: | |
double findMedianSortedArrays(int A[], int m, int B[], int n) { | |
if((n + m) % 2 == 0) { | |
return (findkth(A, m, B, n, (m+n)/2) + findkth(A, m, B, n, (m+n)/2 + 1))*0.5; | |
} else { | |
return findkth(A, m, B, n, (m+n)/2 + 1); | |
} | |
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: | |
int lengthOfLongestSubstring(string s) { | |
int len = s.length(); | |
if(len == 0) return 0; | |
int start = 0; int end = 0; | |
vector<bool> exist(256, false); | |
int totalMax = INT_MIN; | |
for(int start = 0; start < len; start++){ | |
if(!exist[s[start]]) { |
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: | |
ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) { | |
return addTwoNumbersHelper(l1, l2, 0); | |
} | |
ListNode *addTwoNumbersHelper(ListNode *l1, ListNode *l2, int carry) { |
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: | |
string longestPalindrome(string s) { | |
string result; | |
int len = s.length(); | |
for(int i = 0; i < len; i++) { | |
longestPalindromeHelper(s, i, i, result); |
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: | |
string convert(string s, int nRows) { | |
if(nRows == 1) return s; | |
int len = s.length(); | |
vector<string > board(nRows, ""); | |
int direction = 1; | |
int row = -1; |
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: | |
int reverse(int x) { | |
if(x < 0) return reverse(-x) * -1; | |
int temp = 0; | |
while(x > 0) { | |
temp = temp * 10 + x %10; | |
x = x / 10; |
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 isDigit(const char p) { | |
return p >= '0' && p <= '9'; | |
} | |
bool multipleTen(int & input, int sign) { | |
int temp = input; |
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 matchCurrent(const char * s, const char * p) { | |
return *s == *p || ( *p == '.' && *s != '\0'); // *s != '\0' is very important | |
} | |
bool isMatch(const char * s, const char * p) { |
NewerOlder