Java solution only using iterators

  • 0
    public class Vector2D implements Iterator<Integer> {
        Iterator<List<Integer>> it1;
        Iterator<Integer> it2;
        public Vector2D(List<List<Integer>> vec2d) {
            it1 = vec2d.iterator();
            if(it1.hasNext()) it2 =;
        public Integer next() {
        public boolean hasNext() {
            if(it2 == null) return false;
            while(!it2.hasNext() && it1.hasNext()) it2 =;
            return it2.hasNext();

Log in to reply

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