Skip to content

Latest commit

 

History

History
41 lines (28 loc) · 1.02 KB

20200822.md

File metadata and controls

41 lines (28 loc) · 1.02 KB

Algorithm

二维数组中的查找

Description

在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。

Solution

public class Solution {
    public boolean Find(int target, int [][] array) {
        int cloum = array[0].length-1;
        int row = 0;
        while(cloum>=0&&row<array.length){
            if(array[row][cloum]==target){
                return true;
            }else if (array[row][cloum]<target){
                row++;
            }else if(array[row][cloum]>target){
                cloum--;
            }
        }
        return false;
    }
}

Discuss

每次

Review

Tip

Share