• 剑指offer


    题目描述

    在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
    /* 思路
    * 矩阵是有序的,从左下角来看,向上数字递减,向右数字递增,
    * 因此从左下角开始查找,当要查找数字比左下角数字大时。右移
    * 要查找数字比左下角数字小时,上移
    */
    //从左下角开始遍历,比它大向右找,比它小向上找
     
        public boolean Find(int target, int [][] array) {
            int m = array.length;
            int n = array[0].length; //建议修改名字为 rowCount 、colCount 
            
            for (int i = m-1, j= 0; i >=0 && j < n;) {
                
                    if (target > array[i][j]) {
                        j++;
                    } else if (target < array[i][j]) {
                        i--;
                    } else {
                        return true;
                    }
                    
            }
            
            return false;
    
    
        }
  • 相关阅读:
    iscroll.js & flipsnap.js
    IE8’s Substr() Bug
    chrome扩展,如何阻止浏览自动关闭桌面通知.
    临时邮箱
    多个显示器, window.open的定位
    页面刷新
    PipelineDB Install and Test
    CitusDB UPSERT
    Kafka部署
    ambari-cassandra-service
  • 原文地址:https://www.cnblogs.com/AbelZone/p/7676490.html
Copyright © 2020-2023  润新知