C# solution in 4 lines


  • 0
    G
    public class Vector2D {
       private Queue<int>  q;
    
       public Vector2D(IList<IList<int>> vec2d) {
           q = new Queue<int>(vec2d.SelectMany(x => x));
       }
    
       public bool HasNext() {
           return q.Any();
       }
    
       public int Next() {
           return q.Dequeue();
       }
    }

  • 0

    Copy list is not a good idea. It's roughly O(n) on init.


Log in to reply
 

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