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) { | |
enum InputType{ | |
INVALID,//0 | |
SPACE,//1 | |
DIGIT,//2 | |
SIGN,//3 | |
DOT,//4 | |
EXPONET,//5 |
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 total=m+n; | |
if(total&1) | |
return findKth(A,m,B,n,total/2+1); | |
else | |
return (findKth(A,m,B,n,total/2)+findKth(A,m,B,n,total/2+1))/2; | |
} | |
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 sortColors(int A[], int n) { | |
int i=-1; | |
int j=n; | |
int cur=0; | |
while(cur<j) | |
{ | |
if(A[cur]==0)swap(A[++i],A[cur++]); | |
else if(A[cur]==2)swap(A[cur],A[--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: | |
vector<vector<int> > result; | |
vector<vector<int> > permute(vector<int> &num) { | |
permute(num,0); | |
return result; | |
} | |
void permute(vector<int> &num,int 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: | |
vector<vector<int> > result; | |
vector<vector<int> > permuteUnique(vector<int> &num) { | |
permute(num,0); | |
return result; | |
} | |
void permute(vector<int> &num,int 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: | |
void nextPermutation(vector<int> &num) { | |
for(int i=num.size()-1;i-1>=0;--i) | |
{ | |
if(num[i]>num[i-1])//找到最大的降序后缀 1[2]876530 | |
{ | |
for(int j=num.size()-1;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: | |
string getPermutation(int n, int k) { | |
string re(n,'0'); | |
int fac=factorial(n); | |
vector<int> vecNum(n,0); | |
for(int i=1;i<=vecNum.size();++i)vecNum[i-1]=i; | |
--k;// k=[0,(n-i)! ) ,inorder to get the right index | |
for(int i=0;i<n;++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
#include <iostream> | |
#include <fstream> | |
#include <vector> | |
using namespace std; | |
unsigned int merge(vector<int>&nums,int begin,int middle,int end) | |
{ | |
vector<int> left(nums.begin()+begin,nums.begin()+middle); | |
vector<int> right(nums.begin()+middle,nums.begin()+end); |
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
# -*- coding: utf-8 -*- | |
#test on python 3.4 ,python of lower version has different module organization. | |
import http.server | |
from http.server import HTTPServer, BaseHTTPRequestHandler | |
import socketserver | |
PORT = 8080 | |
Handler = http.server.SimpleHTTPRequestHandler |
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
;Code from http://mikeos.berlios.de/write-your-own-os.html | |
;See my cool solution to boot this 'OS‘,i think it's much cool. | |
; http://haiyangxu.github.io/posts/2014/2014-05-21-write_a_bootloader | |
BITS 16 | |
start: | |
mov ax, 07C0h ; Set up 4K stack space after this bootloader | |
add ax, 288 ; (4096 + 512) / 16 bytes per paragraph | |
mov ss, ax |
OlderNewer