摘要:
void swap(int* a,int* b){ int tmp = *a; *a = *b; *b = tmp;}class Solution {public: int removeElement(int A[], int n, int elem) { // Note: The Solution object is instantiated only once and is reused by each test case. int i = 0; int j = n; while(i<j) { ... 阅读全文
摘要:
int threeSumClosest(vector &num, int target) { // Note: The Solution object is instantiated only once and is reused by each test case. sort(num.begin(),num.end()); int i,j,k; int sum,cursum; int curDiff = INT_MAX; for(i=0;itarget) k--;... 阅读全文
摘要:
int atoi(const char *str) { // Note: The Solution object is instantiated only once and is reused by each test case. //skip whitespace const char* p = str; while(*p==' ') ++p; if(*p!='+'&&*p!='-'&&!isdigit(*p)) return 0; bool bNeg... 阅读全文
摘要:
O(n)的解法。详情见:http://www.felix021.com/blog/read.php?2040 string longestPalindrome(string s) { // Note: The Solution object is instantiated only once and is reused by each test case. if(s.empty()) return ""; int mx,i,id; //construct p.Transform S into T.For exa... 阅读全文
摘要:
findKthTwoSortedArray的应用。double findMedianSortedArrays(int A[], int m, int B[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if(((m+n)&0x1)!=0) //odd { return findKthSortedArrays(A,m,B,n,(m+n+1)>>1); }else ... 阅读全文