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

二维数组中的查找

http://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e

一开始就想着肯定有技巧 想不出来只能暴力 无奈二分多么奇妙多么灵活

function Find(target, array)
{
    // write code here
    let bottom=array.length-1
    let right=array[0].length-1
    let n=right
    let m=0
    let pivot
    while(m<=bottom && n>=0){
     pivot=array[m][n]
    if(target===pivot){
        return true
    }
    if(target>pivot) {
        m+=1
    }
    if(target<pivot){
       n-=1
    }       
  }
    return false
}
module.exports = {
    Find : Find
};
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务