题解|#二维数组中的查找#

二维数组中的查找

https://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e?tpId=265&&tqId=39208&rp=1&ru=/ta/coding-interviews-all&qru=/ta/coding-interviews-all/question-ranking

先去除不符合的列,再去除不符合的行,直到遍历完

public class Solution {
    public boolean Find(int target, int [][] array) {

        for(int i = array.length-1; i >= 0; i--){
            
            if(array[i].length < 1){
                return false;
            }
            
            if(array[i][0] > target){
                continue;
            }
            
            for(int j = 0; j < array[i].length; j++){
                
                if(array[i][j] == target){
                    return true;
                }
                
                if(array[i][j] < target){
                    continue;
                }
                
                
            }
            
        }
        
        return false;
    }
    
    
}
全部评论

相关推荐

双尔:反手回一个很抱歉,经过慎重考虑,您与我的预期暂不匹配,感谢您的投递
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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