Skip to content

Instantly share code, notes, and snippets.

@simonwoo
Last active October 16, 2016 12:59
Show Gist options
  • Save simonwoo/493a18e7028027983598852c7bf41cc0 to your computer and use it in GitHub Desktop.
Save simonwoo/493a18e7028027983598852c7bf41cc0 to your computer and use it in GitHub Desktop.

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

例子: 查找数字7 -> true;查找数字5 -> false。

1 2 8 9
2 4 9 12
4 7 10 13
6 8 11 15

总结规律:

  • 首先选取右上角的数字,如果该数字等与要查找的数字,查找过程结束;
  • 如果该数字大于要查找的数字,剔除这个数字所在的列;
  • 如果数字小于要查找的数字,剔除这个数字所在的行。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment