Flatten 2D Vector Posted on 2018-10-20 Descriptionhttps://leetcode.com/problems/flatten-2d-vector/ Solution1234567891011121314151617181920212223242526272829303132333435class Vector2D {private: vector<vector<int>> vec; vector<vector<int>>::iterator rowIter; vector<int>::iterator columnIter;public: Vector2D(vector<vector<int>>& vec2d) { vec = vec2d; rowIter = vec.begin(); while (rowIter != vec.end() && rowIter->size() == 0) ++rowIter; if (rowIter != vec.end()) columnIter = rowIter->begin(); } int next() { int ret = *columnIter; ++columnIter; if (columnIter == rowIter->end()) { ++rowIter; while (rowIter != vec.end() && rowIter->size() == 0) ++rowIter; if (rowIter != vec.end()) columnIter = rowIter->begin(); } return ret; } bool hasNext() { if (rowIter == vec.end()) return false; return true; }};/** * Your Vector2D object will be instantiated and called as such: * Vector2D i(vec2d); * while (i.hasNext()) cout << i.next(); */