package leetcode;

import java.util.Iterator;
import java.util.List;

/**
 * @author fredy
 */
public class Problem341 {
    public interface NestedInteger {
        // @return true if this NestedInteger holds a single integer, rather than a nested list.
        public boolean isInteger();

        // @return the single integer that this NestedInteger holds, if it holds a single integer
        // Return null if this NestedInteger holds a nested list
        public Integer getInteger();

        // @return the nested list that this NestedInteger holds, if it holds a nested list
        // Return null if this NestedInteger holds a single integer
        public List<NestedInteger> getList();
    }

    public static class NestedIterator implements Iterator<Integer> {
        public NestedIterator(List<NestedInteger> nestedList) {
            // TODO
        }

        @Override
        public Integer next() {
            // TODO:
            return null;
        }

        @Override
        public boolean hasNext() {
            // TODO:
            return false;
        }
    }

    public static void main(String[] args) {
        NestedIterator i = new NestedIterator(null);
        while (i.hasNext()) {
            System.out.println(i.next());
        }
    }
}

@@ -12,16 +12,44 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0A
 import j
@@ -102,21 +102,67 @@
 %0A * 
-@author fredy
+https://leetcode.com/problems/flatten-nested-list-iterator/
 %0A */
@@ -843,16 +843,67 @@
 eger%3E %7B%0A
+        private final Iterator%3CInteger%3E iterator;%0A%0A
         
@@ -970,23 +970,505 @@
         
-// TODO
+List%3CInteger%3E list = new ArrayList%3C%3E();%0A            populateIntegerList(nestedList, list);%0A            iterator = list.iterator();%0A        %7D%0A%0A        private void populateIntegerList(List%3CNestedInteger%3E nestedList, List%3CInteger%3E list) %7B%0A            for (NestedInteger ni : nestedList) %7B%0A                if (ni.isInteger()) %7B%0A                    list.add(ni.getInteger());%0A                %7D else %7B%0A                    populateIntegerList(ni.getList(), list);%0A                %7D%0A            %7D
 %0A       
@@ -1537,40 +1537,30 @@
     
-// TODO:%0A            return null
+return iterator.next()
 ;%0A  
@@ -1637,227 +1637,32 @@
     
-// TODO:%0A            return false;%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        NestedIterator i = new NestedIterator(null);%0A        while (i.hasNext()) %7B%0A            System.out.println(i.next()
+return iterator.hasNext(
 );%0A 

Solve problem 341