C# 15 lines added


  • 1
    H
    public class Vector2D {
        IList<IList<int>> vec2d = null;
        int i = -1; // pointer to current list
        int j = 0; // pointer of current element
        
        public Vector2D(IList<IList<int>> vec2d) {
            this.vec2d = vec2d;
            while (++i < vec2d.Count)
                while (j < vec2d[i].Count)
                    return;
        }
    
        public bool HasNext() {
            return i < this.vec2d.Count;
        }
    
        public int Next() {
            int result = vec2d[i][j++];
            while (i < vec2d.Count) {
                while (j < vec2d[i].Count)
                    return result; 
                i++;
                j=0;
            }
            return result;
        }
    }

  • 0

    Great balance between concise and readable in C# code.


Log in to reply
 

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