[Locked] Flatten 2D Vector

时间:2023-02-18 18:42:08

Problem Description:

  Implement an iterator to flatten a 2d vector.

For example,
Given 2d vector =

[
[1,2],
[3],
[4,5,6]
]

By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1, 2, 3, 4, 5, 6].

代码:

class Iterator {
private:
int i, j;
vector<vector<int> > v;
public:
Iterator(vector<vector<int> > &vv) {
i = j = ;
copy(vv.begin(), vv.end(), v.begin());
}
bool hasNext() {
return i < v.size();
}
int next() {
int nextVal = v[i][j];
if(++j == v[i].size()) {
j = ;
++i;
}
return nextVal;
}
};

[Locked] Flatten 2D Vector的更多相关文章

  1. &lbrack;LeetCode&rsqb; Flatten 2D Vector 压平二维向量

    Implement an iterator to flatten a 2d vector. For example,Given 2d vector = [ [1,2], [3], [4,5,6] ] ...

  2. Flatten 2D Vector

    Implement an iterator to flatten a 2d vector. For example, Given 2d vector = [ [1,2], [3], [4,5,6] ] ...

  3. LeetCode Flatten 2D Vector

    原题链接在这里:https://leetcode.com/problems/flatten-2d-vector/ 题目: Implement an iterator to flatten a 2d v ...

  4. 251&period; Flatten 2D Vector

    题目: Implement an iterator to flatten a 2d vector. For example,Given 2d vector = [ [1,2], [3], [4,5,6 ...

  5. &lbrack;Swift&rsqb;LeetCode251&period;展平二维向量 &dollar; Flatten 2D Vector

    Implement an iterator to flatten a 2d vector. For example,Given 2d vector = [ [1,2], [3], [4,5,6] ] ...

  6. 251&period; Flatten 2D Vector 平铺二维矩阵

    [抄题]: Implement an iterator to flatten a 2d vector. Example: Input: 2d vector = [ [1,2], [3], [4,5,6 ...

  7. LeetCode 251&period; Flatten 2D Vector

    原题链接在这里:https://leetcode.com/problems/flatten-2d-vector/ 题目: Implement an iterator to flatten a 2d v ...

  8. Flatten 2D Vector -- LeetCode

    Implement an iterator to flatten a 2d vector. For example,Given 2d vector = [ [,], [], [,,] ] By cal ...

  9. &lbrack;LeetCode&rsqb; 251&period; Flatten 2D Vector 压平二维向量

    Implement an iterator to flatten a 2d vector. For example,Given 2d vector = [ [1,2], [3], [4,5,6] ] ...

随机推荐

  1. Android的NDK技术

    Android的NDK技术

  2. Qt 释放新建窗口资源

    当Widget *w = new Widget(); 不方便调用 delete w;时 Widget *w = new Widget(); w->setAttribute(Qt::WA_Dele ...

  3. Android lint具 常见问题检查

    1. Correctness 1) DuplicatedIds Layout于id应该唯一 2) NewApi 代码中使用的某些API高于Manifest中的Min SDK 3) Inconsiste ...

  4. 6 python高级数据处理和可视化

    6.2. pyplot作图 1.折线图和散点图 t = np.arange(0,4,0.1) plt.plot(t,t,'o',t,t+2,t,t**2,'o') plt.show() 2.柱线图 p ...

  5. layui loading

    layer.msg('加载中', { icon: 16 ,shade: 0.4}); layer.load(2);风格二 setTimeout(function(){ layer.closeAll(' ...

  6. 做到让DBCP连接池不超时

    前些天部署了一个项目,但每次隔一段时间打开都会报如下所示的错误:  javax.servlet.ServletException: org.springframework.transaction.Ca ...

  7. retrofit 基础使用

    1.先导入依赖 加上网络权限 <uses-permission android:name="android.permission.INTERNET" /> 2.创建接口 ...

  8. POJ3189 Steady Cow Assignment

    Steady Cow Assignment Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6817   Accepted:  ...

  9. bigdecimal 与long int 之间转换

    BigDecimal与Long.int之间的互换 在实际开发过程中BigDecimal是一个经常用到的数据类型,它和int Long之间可以相互转换. 转换关系如下代码展示: int 转换成 BigD ...

  10. 配置linux DNS

    DNS服务器地址配置 在Linux下面,有一个默认的DNS服务器地址配置文件的设置,存放在 /etc/resolv.conf 设置方法很简单,通过编辑 vi /etc/resolv.conf 设置首选 ...