当前位置:网站首页>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;
}
};
边栏推荐
猜你喜欢

杭电校赛(逆袭指数)

eNSP-小型网络拓扑(DNS、DHCP、网站服务器、无线路由器)

CCF GLCC officially opened | Kyushu Cloud open source experts bring generous bonuses to help universities promote open source

数据链路层-------以太网协议

Sum of four squares, laser bombs

【Today in History】August 4: First female Turing Award winner; NVIDIA acquires MediaQ; first Cybersecurity Challenge completed

Basic Introduction for PLSQL

【HMS core】【Media】【视频编辑服务】 在线素材无法展示,一直Loading状态或是网络异常

Qt的QItemDelegate使用

idea去掉spark的日志
随机推荐
FRED应用:毛细管电泳系统
【模型部署与业务落地】基于量化芯片的损失分析
F. Jinyu and its outer matrix (construction)
The Internet of things application development trend
vim 常用操作命令
实际工作中的高级技术(训练加速、推理加速、深度学习自适应、对抗神经网络)
基本介绍PLSQL
【历史上的今天】8 月 4 日:第一位图灵奖女性得主;NVIDIA 收购 MediaQ;首届网络安全挑战大赛完成
js深拷贝和浅拷贝具体使用区别_es6深拷贝和浅拷贝
leetcode: 212. Word Search II
Workaround without Project Facets
【剑指offer59】队列的最大值
快解析结合千方百剂
NPDP|作为产品经理,如何快速提升自身业务素养?
【问题解决】QT更新组件出现 “要继续此操作,至少需要一个有效且已启用的储存库”
Cisco - Small Network Topology (DNS, DHCP, Web Server, Wireless Router)
Technology sharing | Mini program realizes audio and video calls
异步编程概览
G.登山小分队(暴力&dfs)
1401 - Web technology 】 【 introduction to graphical Canvas