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

二维数组中的查找

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

using System;
using System.Collections.Generic;
using System.Linq;
class Solution {
public bool Find (int target, List<List<int>> array) {
int row = array.Count();//行数
int col = array[0].Count();//列数
if(row==0)return false;
if(col==0)return false;
//注意很多人这里数组越界
if(target<array[0][0]||target>array[row-1][col-1])return false;
for(int i=0;i<row;i++)
{
for(int j=col-1;j>=0;j--)
{
if(target > array[i][j])break;
if(target == array[i][j])return true;
}
}
return false;
}
}</int>

全部评论

相关推荐

哇哇的菜鸡oc:他这不叫校招offer,而是实习offer
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务