当前位置:网站首页>leetcode: 251. Expanding 2D Vectors
leetcode: 251. Expanding 2D Vectors
2022-08-04 14:37:00 【OceanStar's study notes】
题目来源
题目描述
题目解析
class Vector2D {
std::vector<std::vector<int>> m;
int row;
int col; //迭代器光标位置
bool canUse; //Whether the position pointed to by the cursor has already been used
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; //Exceeded terminating line
}
if(!canUse){
//The current number has not been used yet
return true;
}
// (row, col) 被使用过了, Going to the next one
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; //to the end line
}
}
int next(){
int ans = m[row][col];
canUse = true;
has_next();
return ans;
}
};
边栏推荐
猜你喜欢
leetcode: 253. How many meeting rooms are required at least
爬虫——selenium基本使用、无界面浏览器、selenium的其他用法、selenium的cookie、爬虫案例
利用决策树找出最优特征组合
Google plug-in. Download contents file is automatically deleted after solution
一看就会的Chromedriver(谷歌浏览器驱动)安装教程
16、学习MySQL 正则表达式
物联网应用发展趋势
Sum of four squares, laser bombs
X射线掠入射聚焦反射镜
centos7安装mysql急速版
随机推荐
leetcode:259. 较小的三数之和
[Problem solving] QT update component appears "To continue this operation, at least one valid and enabled repository is required"
解题-->在线OJ(十八)
2042. 检查句子中的数字是否递增-力扣双百代码-设置前置数据
7 天找个 Go 工作,Gopher 要学的条件语句,循环语句 ,第3篇
Hangzhou electric the competition team arrangement (ACM)
FRED应用:毛细管电泳系统
How to fall in love with a programmer
Android Sqlite3基本命令
idea removes spark logs
AOSP built-in APP franchise rights white list
异步编程概览
四平方和,激光炸弹
Makefile 语法及使用笔记
xampp安装包含的组件有(php,perl,apche,mysql)
Technology sharing | Description of the electronic fence function in the integrated dispatching system
基于 Next.js实现在线Excel
爬虫——selenium基本使用、无界面浏览器、selenium的其他用法、selenium的cookie、爬虫案例
leetcode:250. 统计同值子树
[The Art of Hardware Architecture] Study Notes (1) The World of Metastability