二维数组中的查找

来源:互联网 发布:php 分页偏移量 编辑:程序博客网 时间:2024/06/03 20:46

题目有一种固定变量的思想,先看某一个维度,然后不断调整

public class Solution {    public boolean Find(int target, int[][] array) {        if(array == null) return false;        int rows = array.length;        int columns = array[0].length;        int row = 0;        int column = columns-1;        while (row < rows && column>=0) {            int k = array[row][column];            if(k==target) return true;            else if(k > target) --column;            else if(k < target) ++row;        }        return false;    }}
原创粉丝点击