当前位置:网站首页>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;
}
};
边栏推荐
- G. Mountaineering Squad (violence & dfs)
- 期货开户之前要谈好最低手续费和交返
- X射线掠入射聚焦反射镜
- [in-depth study of 4 g / 5 g / 6 g project - 50] : URLLC - 16 - the 3 GPP URLLC agreement, specification, technical principle of depth interpretation - 10 - high reliability technology - 1 - low codin
- 南瓜科学产品升级 开启益智探索新篇章
- The Internet of things application development trend
- MySQL【窗口函数】【共用表表达式】
- C# 动态加载卸载 DLL
- 1375. 二进制字符串前缀一致的次数-前序遍历法
- Sum of four squares, laser bombs
猜你喜欢

《中国综合算力指数》《中国算力白皮书》《中国存力白皮书》《中国运力白皮书》在首届算力大会上重磅发出

【Web技术】1401- 图解 Canvas 入门

小 P 周刊 Vol.13

爬虫——selenium基本使用、无界面浏览器、selenium的其他用法、selenium的cookie、爬虫案例

Google plug-in. Download contents file is automatically deleted after solution

【剑指offer33】二叉搜索树的后序遍历序列

eyb:JWT介绍

四平方和,激光炸弹

Win11勒索软件防护怎么打开?Win11安全中心勒索软件防护如何设置

利用决策树找出最优特征组合
随机推荐
相似文本聚类与调参
Theory 1: Deep Learning - Detailed Explanation of the LetNet Model
阴影初始化【5】
Centos7 install mysql version rapidly
[深入研究4G/5G/6G专题-50]: URLLC-16-《3GPP URLLC相关协议、规范、技术原理深度解读》-10-高可靠性技术-1-低编码率编码调制方案MCS与高可靠性DRB
第六届未来网络发展大会,即将开幕!
【北亚数据恢复】IBM System Storage存储lvm信息丢失数据恢复方案
Android Sqlite3 basic commands
【硬件架构的艺术】学习笔记(1)亚稳态的世界
杭电校赛(逆袭指数)
[in-depth study of 4 g / 5 g / 6 g project - 50] : URLLC - 16 - the 3 GPP URLLC agreement, specification, technical principle of depth interpretation - 10 - high reliability technology - 1 - low codin
快解析结合千方百剂
idea removes spark logs
Technology sharing | Description of the electronic fence function in the integrated dispatching system
vim common operation commands
一看就会的Chromedriver(谷歌浏览器驱动)安装教程
CF1527D MEX Tree (mex & tree & inclusive)
【HMS core】【Media】【视频编辑服务】 在线素材无法展示,一直Loading状态或是网络异常
本周讨论用户体验:Daedalus 的 Nemo 加入 Ambire,探索加密海洋
电子行业MES管理系统有哪些特殊功能