Very easy understand Java solution using a queue to store int

  • 0
            private LinkedList<Integer> queue = new LinkedList<Integer>();
    	public ZigzagIterator(List<Integer> v1, List<Integer> v2) {
    		int size = Math.max(v1.size(), v2.size());		
    		for (int i = 0; i < size; i++) {
    			if (i<v1.size())
    			if (i<v2.size())
    	public int next() {
    		return queue.pop();
    	public boolean hasNext() {
    		return !queue.isEmpty();

Log in to reply

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