C++_AC


  • 0
    class Vector2D {
    vector<vector<int>> vec2d;
    int x = 0, y = 0;
    public:
    Vector2D(vector<vector<int>>& vec2d) {
        this->vec2d = vec2d;
    }
    
    int next() {
        return vec2d[x][y++];
    }
    
    bool hasNext() {
        if(vec2d.empty()) return false;
        if(y == vec2d[x].size()){y = 0; x++;}
        if(x < vec2d.size() && !vec2d[x].empty()){
            return true;
        }else{
            while(x < vec2d.size() && vec2d[x].empty()){
                x++;
            }
            y = 0;
        }
        return x < vec2d.size();
    }
    };

Log in to reply
 

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