Xu2333

 

空着怪冷清的!贴贴代码吧~

Leetcode_4:

class Solution {
public:
    double findMedianSortedArrays(int A[], int m, int B[], int n) {
    	int len = m+n;
    	if (len & 1){
    		return my_find(A,m,B,n,(len >> 1)+1);
    	} else {
    		return (double(my_find(A,m,B,n,len >> 1)) + my_find(A,m,B,n,(len >> 1)+1))/2;
    	}
    }
    
    double my_find(int A[], int m, int B[], int n, int k){
    	if (m>n) return my_find(B,n,A,m,k);
    	if (m==0) return B[k-1];
    	if (k==1) return A[0]<B[0]?A[0]:B[0];
    	int ma = k/2<m?k/2:m;
    	int mb = k - ma;
    	if (A[ma-1]==B[mb-1]) return A[ma-1];
        if (A[ma-1]<B[mb-1])
            return my_find(A+ma, m-ma, B, mb, k-ma);
        else
            return my_find(A, ma, B+mb, n-mb, k-mb);
    }
};

  

 

Leetcode_10:

class Solution {
public:
    bool isMatch(const char *s, const char *p) {
    	if (*s=='\0' && *p=='\0') return true;
        else if (*s!='\0' || *p!='\0'){
        	if (*p=='\0') return false;
        	if (*(p+1)=='*'){
        		if (isMatch(s,p+2)) return true;
				if ((*s!='\0') && (*p=='.' || *s==*p)) return isMatch(s+1,p);
        		return false;
        	}
        	else{
        		if ((*s!='\0') && (*p=='.' || *s==*p)) return isMatch(s+1,p+1);
        		return false;
        	}
		}
		else return false;	
	}
};

  

posted on 2015-03-30 21:12  Xu2333  阅读(132)  评论(0编辑  收藏  举报

导航