码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-03-30 22:46:29      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

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;	
	}
};

  

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

标签:

原文地址:http://www.cnblogs.com/Xu2334/p/4379185.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!