空气床店面

题目如下:

Implement Iterator class with methods hasNext(), next(), remove() over a list of lists. next() should return the next element, remove() should remove the current element.

var list = new List<List<int>>();
list.Add(new List<int>());
list.Add(new List<int>());
list.Add(new List<int>() {1, 2});
list.Add(new List<int>());
list.Add(new List<int>() {3, 4, 5});

var iterator = new Iterator(list);
Console.WriteLine(iterator.next()); // 1
Console.WriteLine(iterator.remove()); // removes 2 from the list
Console.WriteLine(iterator.next()); // 3

40 分钟

参考