当前位置:网站首页>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;
}
};
边栏推荐
- B.构造一个简单的数列(贪心)
- Android Sqlite3基本命令
- CF1527D MEX Tree (mex & tree & inclusive)
- 【剑指offer59】队列的最大值
- Lecture 4 SVN
- ASA归因:如何评估关键词的投放价值
- SLAM 05.视觉里程计-2-特征法
- CCF GLCC officially opened | Kyushu Cloud open source experts bring generous bonuses to help universities promote open source
- 【北亚数据恢复】IBM System Storage存储lvm信息丢失数据恢复方案
- 编程思想_编程有必要给孩子学吗?
猜你喜欢
随机推荐
物联网应用发展趋势
AOSP内置APP特许权限白名单
Lecture 4 SVN
如何在ubuntu环境下安装postgresql并配置远程访问
Rust 从入门到精通04-变量
开发者独立搭建一个跨模态搜索应用有多难?
MySQL性能指标TPS\QPS\IOPS如何压测?
js深拷贝和浅拷贝具体使用区别_es6深拷贝和浅拷贝
爬虫——动作链、xpath、打码平台使用
【历史上的今天】8 月 4 日:第一位图灵奖女性得主;NVIDIA 收购 MediaQ;首届网络安全挑战大赛完成
vim 常用操作命令
实际工作中的高级技术(训练加速、推理加速、深度学习自适应、对抗神经网络)
代码随想录笔记_动态规划_1049最后一块石头的重量II
[Problem solving] QT update component appears "To continue this operation, at least one valid and enabled repository is required"
G.登山小分队(暴力&dfs)
量化细胞内的信息流:机器学习时代下的研究进展
第十六章 源代码文件 REST API 教程(一)
【Web技术】1401- 图解 Canvas 入门
Why does the decimal point appear when I press the space bar in word 2003?
Technology sharing | Description of the electronic fence function in the integrated dispatching system









