Guest User

Untitled

a guest
Jul 17th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. class NestedIterator {
  2. public:
  3. int len;
  4. queue<int> st;
  5. NestedIterator(vector<NestedInteger> &nestedList) {
  6. len = nestedList.size();
  7. hello(nestedList,len);
  8. }
  9. void hello(vector<NestedInteger> &nestedList,int len)
  10. {
  11. for(int i=0;i<len;i++)
  12. {
  13. if(nestedList[i].isInteger())
  14. st.push(nestedList[i].getInteger());
  15. else
  16. {
  17. vector<NestedInteger> vec = nestedList[i].getList();
  18. hello(vec,vec.size());
  19. }
  20. }
  21. }
  22. int next() {
  23. if(hasNext())
  24. {
  25. int t = st.front();
  26. st.pop();
  27. return t;
  28. }
  29.  
  30. }
  31.  
  32. bool hasNext() {
  33. return !(st.empty());
  34. }
  35. };
Add Comment
Please, Sign In to add comment