Skip to content

Instantly share code, notes, and snippets.

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;
}
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);
}
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]]) {
class Solution {
public:
ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) {
return addTwoNumbersHelper(l1, l2, 0);
}
ListNode *addTwoNumbersHelper(ListNode *l1, ListNode *l2, int carry) {
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);
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;
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;
class Solution {
public:
bool isDigit(const char p) {
return p >= '0' && p <= '9';
}
bool multipleTen(int & input, int sign) {
int temp = input;
class Solution {
public:
bool isPalindrome(int x) {
if(x == 0) return true;
if(x < 0) return false; // not isPalindrome(-x)
int factor = 1;
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) {