Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NestedIterator {
- public:
- int len;
- queue<int> st;
- NestedIterator(vector<NestedInteger> &nestedList) {
- len = nestedList.size();
- hello(nestedList,len);
- }
- void hello(vector<NestedInteger> &nestedList,int len)
- {
- for(int i=0;i<len;i++)
- {
- if(nestedList[i].isInteger())
- st.push(nestedList[i].getInteger());
- else
- {
- vector<NestedInteger> vec = nestedList[i].getList();
- hello(vec,vec.size());
- }
- }
- }
- int next() {
- if(hasNext())
- {
- int t = st.front();
- st.pop();
- return t;
- }
- }
- bool hasNext() {
- return !(st.empty());
- }
- };
Add Comment
Please, Sign In to add comment