-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution341.java
More file actions
32 lines (26 loc) · 772 Bytes
/
Copy pathsolution341.java
File metadata and controls
32 lines (26 loc) · 772 Bytes
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
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
public class solution341 {
Queue<Integer> queue = new LinkedList<>();
public solution341(List<NestedInteger> nestedList) {
resolve(nestedList);
}
public void resolve(List<NestedInteger> nestedList){
for(int i=0;i<nestedList.size();i++){
NestedInteger nestedInteger = nestedList.get(i);
if(nestedInteger.isInteger()){
queue.add(nestedInteger.getInteger());
}else{
resolve(nestedInteger.getList());
}
}
}
public Integer next() {
return queue.poll();
}
public boolean hasNext() {
return !queue.isEmpty();
}
}