当前位置:网站首页>Nc29 search in two-dimensional array
Nc29 search in two-dimensional array
2022-07-06 09:40:00 【I'm not Xiao Haiwa~~~~】

describe
In a two-dimensional array array in ( Each one-dimensional array has the same length ), Each row is sorted in ascending order from left to right , Each column is sorted in ascending order from top to bottom . Please complete a function , Enter such a two-dimensional array and an integer , Determine whether the array contains the integer .
[
[1,2,8,9],
[2,4,9,12],
[4,7,10,13],
[6,8,11,15]
]
Given target = 7, return true.
Given target = 3, return false.

Advanced : Spatial complexity O(1)O(1) , Time complexity O(n+m)O(n+m)
Example 1
Input :
7,[[1,2,8,9],[2,4,9,12],[4,7,10,13],[6,8,11,15]]
Return value :
true
explain :
There is 7, return true
Example 2
Input :
1,[[2]]
Return value :
false
Example 3
Input :
3,[[1,2,8,9],[2,4,9,12],[4,7,10,13],[6,8,11,15]]
Return value :
false
explain :
non-existent 3, return false
Code:
class Solution {
public:
bool Find(int target, vector<vector<int> > array) {
for(int i=0;i<array.size();i++)
{
vector<int> subvec=array[i];
for(int j=0;j<subvec.size();j++)
{
vector<int>::iterator it=find(subvec.begin(),subvec.end(),target);
if(it!=subvec.end())
return true;
}
}
return false;
}
};
边栏推荐
猜你喜欢

Hero League rotation map automatic rotation

Servlet learning diary 7 -- servlet forwarding and redirection

Mapreduce实例(四):自然排序

Le modèle sentinelle de redis

Sqlmap installation tutorial and problem explanation under Windows Environment -- "sqlmap installation | CSDN creation punch in"

33岁可以学PLC吗

Redis cluster

一大波开源小抄来袭

MapReduce instance (VIII): Map end join

发生OOM了,你知道是什么原因吗,又该怎么解决呢?
随机推荐
[deep learning] semantic segmentation: paper reading: (CVPR 2022) mpvit (cnn+transformer): multipath visual transformer for dense prediction
MapReduce instance (x): chainmapreduce
[Yu Yue education] reference materials of complex variable function and integral transformation of Shenyang University of Technology
O & M, let go of monitoring - let go of yourself
Global and Chinese market of bank smart cards 2022-2028: Research Report on technology, participants, trends, market size and share
[Yu Yue education] Wuhan University of science and technology securities investment reference
MapReduce instance (VI): inverted index
Redis之哨兵模式
五月刷题26——并查集
Redis之持久化实操(Linux版)
Kratos战神微服务框架(三)
Sqlmap installation tutorial and problem explanation under Windows Environment -- "sqlmap installation | CSDN creation punch in"
YARN组织架构
为什么要数据分层
Redis cluster
Redis之主从复制
六月刷题02——字符串
Redis core configuration
Design and implementation of online snack sales system based on b/s (attached: source code paper SQL file)
Kratos ares microservice framework (I)