Javascript flatten upfront...am I cheating?


  • 0
    T

    Doubt most interviewers would allow this hehehe

    /**
     * @constructor
     * @param {Integer[][]} vec2d
     */
    var Vector2D = function(vec2d) {
        this.vec2d = [].concat.apply([],vec2d);
    };
    
    
    /**
     * @this Vector2D
     * @returns {boolean}
     */
    Vector2D.prototype.hasNext = function() {
        return this.vec2d.length;
    };
    
    /**
     * @this Vector2D
     * @returns {integer}
     */
    Vector2D.prototype.next = function() {
        return this.vec2d.shift();
    };
    

Log in to reply
 

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