当前位置:网站首页>leetcode:251. 展开二维向量
leetcode:251. 展开二维向量
2022-08-04 14:31:00 【OceanStar的学习笔记】
题目来源
题目描述

题目解析
class Vector2D {
std::vector<std::vector<int>> m;
int row;
int col; //迭代器光标位置
bool canUse; //光标所指位置是否已经被使用过
public:
Vector2D(std::vector<std::vector<int>> v){
m = std::move(v);
row = 0, col = -1;
canUse = true; //认为[0, -1]使用过
has_next();
}
bool has_next(){
if(row == m.size()){
return false; //超过终止行了
}
if(!canUse){
//当前数还没有被使用过
return true;
}
// (row, col) 被使用过了, 要去下一个了
if(col == m[row].size() - 1){
col = 0;
do{
//跳过空行
row++;
}while (row < m.size() && m[row].empty());
}else{
col++;
}
// 新的(row, col)
if(row != m.size()){
canUse = false;
return true;
}else{
return false; //到了终止行
}
}
int next(){
int ans = m[row][col];
canUse = true;
has_next();
return ans;
}
};
边栏推荐
- [Beiya data recovery] IBM System Storage storage lvm information lost data recovery solution
- MySQL性能指标TPS\QPS\IOPS如何压测?
- 杭电校赛(逆袭指数)
- eyb:JWT介绍
- Android Sqlite3 basic commands
- 手搓一个“七夕限定”,用3D Engine 5分钟实现烟花绽放效果
- F. Jinyu and its outer matrix (construction)
- 【硬件架构的艺术】学习笔记(1)亚稳态的世界
- 本周讨论用户体验:Daedalus 的 Nemo 加入 Ambire,探索加密海洋
- 兆骑科创创新创业大赛活动举办,线上直播路演,投融资对接
猜你喜欢
随机推荐
如何确定异步 I/O 瓶颈
16、学习MySQL 正则表达式
OAID是什么
开放麒麟 openKylin 版本规划敲定:10 月发布 0.9 版并开启公测,12 月发布 1.0 版
Almost all known protein structures in the world are open sourced by DeepMind
企业级优化
[Problem solving] QT update component appears "To continue this operation, at least one valid and enabled repository is required"
NPDP|作为产品经理,如何快速提升自身业务素养?
oracle+RAC+linux5.1所需要安装的包
Problem solving-->Online OJ (18)
爬虫——动作链、xpath、打码平台使用
Win11快速助手在哪里?Win11打开快速助手的方法
阿里老鸟终于把测试用例怎么写说的明明白白了,小鸟必看
CF1527D MEX Tree (mex & tree & inclusive)
考研上岸又转行软件测试,从5k到13k完美逆袭,杭州校区小哥哥拒绝平庸终圆梦!
AOSP内置APP特许权限白名单
Notes for xpath getting node with namespace
快解析结合友加畅捷U+
word2003按空格键为什么会出现小数点
Google plug-in. Download contents file is automatically deleted after solution








![[The Art of Hardware Architecture] Study Notes (1) The World of Metastability](/img/ac/54e4e13d9df90e96933c69623b770e.png)
