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 isNumber(const char *s) { | |
if (!s) return false; | |
bool sign = true; bool num = false; | |
bool e = true; bool dot = true; int space = 0; | |
char c; | |
while (c=*s++) { | |
if (c != ' ' && space == 2) return false; |
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
/** | |
* Definition for singly-linked list with a random pointer. | |
* struct RandomListNode { | |
* int label; | |
* RandomListNode *next, *random; | |
* RandomListNode(int x) : label(x), next(NULL), random(NULL) {} | |
* }; | |
*/ | |
typedef RandomListNode Node; | |
class Solution { |
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<string> fullJustify(vector<string> &words, int L) { | |
int N = words.size(); vector<string> ans; | |
for (int i = 0; i < N;) { | |
int n = 1; int len = words[i].size(); | |
for (int j = i+1; j < N; ++j) { | |
if (len + words[j].size() + 1 > L) break; | |
len += words[j].size() + 1; | |
++n; |
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<int> > threeSum(vector<int> &num) { | |
sort(num.begin(), num.end()); | |
vector<vector<int> > ans; | |
int N = num.size(); | |
int pre = INT_MIN; | |
for (int i = 0; i < N; ++i) { | |
if (num[i] == pre) continue; |
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: | |
double findMedianSortedArrays(int A[], int m, int B[], int n) { | |
int N = m+n; | |
if (N%2) return findKth(A, m, B, n, N/2+1); | |
else return (double(findKth(A, m, B, n, N/2)) + findKth(A, m, B, n, N/2+1))/2; | |
} | |
int findKth(int A[], int m, int B[], int n, int k) { | |
if (m > n) return findKth(B, n, A, m, k); | |
if (m==0) return B[k-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: | |
struct InCmp { | |
bool operator()(const Interval & x, const Interval & y) const { | |
return x.start < y.start; | |
} | |
}; | |
vector<Interval> merge(vector<Interval> &v) { | |
if (v.size() == 0) return v; | |
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
/** | |
* Definition for an interval. | |
* struct Interval { | |
* int start; | |
* int end; | |
* Interval() : start(0), end(0) {} | |
* Interval(int s, int e) : start(s), end(e) {} | |
* }; | |
*/ | |
class Solution { |
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
#include <cstdio> | |
#include <string> | |
#include <iostream> | |
#include <map> | |
#include <cstring> | |
#include <vector> | |
#include <cmath> | |
#include <cstdlib> | |
#include <cassert> | |
#include <climits> |
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 isScramble(string s1, string s2) { | |
int N = s1.size(); | |
if (N != s2.size()) return false; | |
if (N == 0) return true; | |
init(N); s1_ = &s1; s2_ = &s2; | |
return judge(0, 0, N); | |
} |
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
int main() | |
{ | |
int n, k; | |
scanf("%d %d", &n, &k); | |
n *= 2; | |
for (int i = 1; i <= n; i+=2) { | |
if (k) { | |
--k; | |
printf("%d %d ", i, i+1); | |
} else |
OlderNewer