当前位置:网站首页>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;
}
};
边栏推荐
- Redis之主从复制
- 美团二面:为什么 Redis 会有哨兵?
- Take you back to spark ecosystem!
- Servlet learning diary 8 - servlet life cycle and thread safety
- 小白带你重游Spark生态圈!
- Global and Chinese markets for small seed seeders 2022-2028: Research Report on technology, participants, trends, market size and share
- 为什么要数据分层
- Mapreduce实例(八):Map端join
- [Yu Yue education] reference materials of complex variable function and integral transformation of Shenyang University of Technology
- [shell script] use menu commands to build scripts for creating folders in the cluster
猜你喜欢
随机推荐
MapReduce working mechanism
Redis' bitmap
Research and implementation of hospital management inpatient system based on b/s (attached: source code paper SQL file)
Redis之核心配置
Redis core configuration
Kratos ares microservice framework (I)
CAP理论
Le modèle sentinelle de redis
Several ways of MySQL database optimization (pen interview must ask)
Blue Bridge Cup_ Single chip microcomputer_ PWM output
[shell script] - archive file script
Libuv thread
为拿 Offer,“闭关修炼,相信努力必成大器
[deep learning] semantic segmentation: thesis reading (neurips 2021) maskformer: per pixel classification is not all you need
Use of activiti7 workflow
Improved deep embedded clustering with local structure preservation (Idec)
Servlet learning diary 8 - servlet life cycle and thread safety
[Yu Yue education] reference materials of power electronics technology of Jiangxi University of science and technology
一大波開源小抄來襲
Solve the problem of inconsistency between database field name and entity class attribute name (resultmap result set mapping)








