题解 | #两个链表生成相加链表#

二维数组中的查找

http://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e

class Solution {
public:

    bool Findnum(vector<int> array, int target)
    {
        int left=0;
        int right=array.size();
        int index = right;
        while(1)
        {
            index = (left+right)/2;
            if(index == left && array[index]!=target) return false; 
            if(array[index]==target) return true;
            else if(array[index]<target) left=index;
            else right=index;
        }
        return false;
    }

    bool Find(int target, vector<vector<int> > array) {
        int col = array[0].size();
        int row = array.size();
        if(col==0) return false;
        for(int i=0;i<row;i++)
        {
            if(array[i][0]==target || array[i][col-1]==target) return true;
            else if(array[i][0]<target && array[i][col-1]>target)
            {
                if(Findnum(array[i],target)==true) return true;
            }
        }
        return false;
    }
};
全部评论

相关推荐

自由水:笑死了,敢这么面试不敢让别人说
点赞 评论 收藏
分享
牛客刘北:如果暑期实习是27届的话,你要晚一年才会毕业,企业为什么会等你呢?要搞清时间逻辑呀!27届现在实习只能是在暑假实习,这是日常实习,不是暑期实习。所以多去投日常实习吧,暑期实习肯定不会要你的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务