Short C++ Solution [No Fancy Stuff]


  • 0
    B
    vector<int> ans;
        int idx = 0;
        
        Vector2D(vector<vector<int>>& vec2d) {
            
            for(int i = 0 ; i < vec2d.size(); i++){
                for(int j = 0 ; j < vec2d[i].size(); j++){
                    ans.emplace_back(vec2d[i][j]);
                }
            }
        }
    
        int next() {
            return ans[idx++];
        }
    
        bool hasNext() {
            return idx < ans.size();
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.