forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_251.java
38 lines (32 loc) · 1015 Bytes
/
_251.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.fishercoder.solutions;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
public class _251 {
public static class Solution1 {
class Vector2D implements Iterator<Integer> {
private Queue<Integer> cache;
private List<List<Integer>> vec2d;
public Vector2D(List<List<Integer>> vec2d) {
this.vec2d = vec2d;
this.cache = new LinkedList<Integer>();
if (vec2d != null && vec2d.size() > 0) {
for (List<Integer> list : vec2d) {
for (int i : list) {
cache.offer(i);
}
}
}
}
@Override
public Integer next() {
return cache.poll();
}
@Override
public boolean hasNext() {
return !cache.isEmpty();
}
}
}
}