当前位置:网站首页>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;
}
};
边栏推荐
- [Beiya data recovery] IBM System Storage storage lvm information lost data recovery solution
- 自监督学习未来是掩码自编码器?KAIST最新《自监督学习掩码自编码器》研究进展
- 基于 Next.js实现在线Excel
- Technology sharing | Description of the electronic fence function in the integrated dispatching system
- 世间几乎所有已知蛋白质结构,都被DeepMind开源了
- 【 HMS core 】 【 Media 】 online video editing service 】 【 material can't show, or network anomalies have been Loading state
- 浙江大学团队使用基于知识图谱的新方法,从空间分辨转录组数据中推断细胞间通信状况
- JCMsuite应用:倾斜平面波传播透过光阑的传输
- How to automatically renew the token after it expires?
- 杭电校赛(ACM组队安排)
猜你喜欢
随机推荐
四平方和,激光炸弹
【北亚数据恢复】IBM System Storage存储lvm信息丢失数据恢复方案
B. Construct a simple sequence (greedy)
属于程序猿的浪漫
1375. 二进制字符串前缀一致的次数-前序遍历法
leetcode: 254. Combinations of factors
How to install postgresql and configure remote access in ubuntu environment
【 HMS core 】 【 Media 】 online video editing service 】 【 material can't show, or network anomalies have been Loading state
期货开户之前要谈好最低手续费和交返
[The Art of Hardware Architecture] Study Notes (1) The World of Metastability
在腾讯,我的试用期总结!
xampp安装包含的组件有(php,perl,apche,mysql)
【剑指offer33】二叉搜索树的后序遍历序列
js深拷贝和浅拷贝具体使用区别_es6深拷贝和浅拷贝
AlphaFold 如何实现 AI 在结构生物学中的全部潜力
基于 Next.js实现在线Excel
G.登山小分队(暴力&dfs)
F.金玉其外矩阵(构造)
CloudCompare&PCL 点云按网格划分(点云分幅)
leetcode:253. 至少需要多少间会议室