74. Search a 2D Matrix

public class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {
        int rows=matrix.length;
        int columns=matrix[0].length;
        boolean res=false;
        for(int i=0;i<rows;i++)
        {
            for(int j=0;j<columns;j++)
            {
                if(matrix[i][j]==target)
                {
                    res=true;
                    break;
                }
            }
            if(res==true)
                break;
        }
        return res;
    }
}

 

posted @ 2016-04-04 14:28  阿怪123  阅读(89)  评论(0编辑  收藏  举报