package leetcode;

import java.util.Iterator;

/**
 * https://leetcode.com/problems/peeking-iterator/
 */
public class Problem284 {
    private static class PeekingIterator implements Iterator<Integer> {
        public PeekingIterator(Iterator<Integer> iterator) {
            // initialize any member here.
        }

        // Returns the next element in the iteration without advancing the iterator.
        public Integer peek() {
            // TODO
            return null;
        }

        // hasNext() and next() should behave the same as in the Iterator interface.
        // Override them if needed.
        @Override
        public Integer next() {
            // TODO
            return null;
        }

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

    public static void main(String[] args) {

    }
}

@@ -210,102 +210,270 @@
    p
-ublic PeekingIterator(Iterator%3CInteger%3E iterator) %7B%0A            // initialize any member here.
+rivate final Iterator%3CInteger%3E iterator;%0A        private Integer peek;%0A%0A        public PeekingIterator(Iterator%3CInteger%3E iterator) %7B%0A            this.iterator = iterator;%0A            if (iterator.hasNext()) %7B%0A                peek = iterator.next();%0A            %7D
 %0A   
@@ -597,36 +597,16 @@
 eek() %7B%0A
-            // TODO%0A
         
@@ -608,36 +608,36 @@
          return 
-null
+peek
 ;%0A        %7D%0A%0A   
@@ -820,39 +820,200 @@
     
-// TODO%0A            return null
+Integer oldPeek = peek;%0A            if (iterator.hasNext()) %7B%0A                peek = iterator.next();%0A            %7D else %7B%0A                peek = null;%0A            %7D%0A            return oldPeek
 ;%0A  
@@ -1090,16 +1090,32 @@
     
-// TODO%0A
+if (peek == null) %7B%0A    
     
@@ -1148,62 +1148,48 @@
     
-%7D%0A
     %7D%0A
-%0A
     
-public static void main(String%5B%5D args) %7B%0A
+        return true;%0A        %7D
 %0A   

Solve problem 284