当前位置:网站首页>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;
}
};
边栏推荐
- Why does the decimal point appear when I press the space bar in word 2003?
- Set partition minimum difference problem (01 knapsack)
- How to install postgresql and configure remote access in ubuntu environment
- [深入研究4G/5G/6G专题-50]: URLLC-16-《3GPP URLLC相关协议、规范、技术原理深度解读》-10-高可靠性技术-1-低编码率编码调制方案MCS与高可靠性DRB
- Android Sqlite3 basic commands
- [The Art of Hardware Architecture] Study Notes (1) The World of Metastability
- 兆骑科创创新创业大赛活动举办,线上直播路演,投融资对接
- 期货开户之前要谈好最低手续费和交返
- leetcode:212. 单词搜索 II
- leetcode: 254. Combinations of factors
猜你喜欢
随机推荐
ICML 2022 | 图神经网络的局部增强
没有Project Facets的解决方法
2042. 检查句子中的数字是否递增-力扣双百代码-设置前置数据
Google plug-in. Download contents file is automatically deleted after solution
How to Identify Asynchronous I/O Bottlenecks
leetcode:255 验证前序遍历序列二叉搜索树
CloudCompare&PCL 点云按网格划分(点云分幅)
metaRTC5.0新版本支持mbedtls(PolarSSL)
vim 常用操作命令
token 过期后,如何自动续期?
7 天能找到 Go 工作吗?学学 Go 数组和指针试试
属于程序猿的浪漫
华为云 & 达达,帮有情人“一键送达”
广告电商系统开发功能只订单处理
leetcode: 254. Combinations of factors
技术分享| 融合调度系统中的电子围栏功能说明
特殊品种的二次开户验资金额
Chinese valentine's day, of course, to learn SQL optimization better leave work early to find objects
杭电校赛(逆袭指数)
7 天找个 Go 工作,Gopher 要学的条件语句,循环语句 ,第3篇








