leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0284.cpp (525B)
0 class PeekingIterator : public Iterator { 1 int l_next = -1; 2 bool has_next = false; 3 4 public: 5 PeekingIterator(const vector<int> &nums) : Iterator(nums) { 6 if (!Iterator::hasNext()) return; 7 l_next = Iterator::next(); 8 has_next = true; 9 } 10 11 int peek() { return l_next; } 12 13 int next() { 14 const int crnt = l_next; 15 has_next = Iterator::hasNext(); 16 if (has_next) l_next = Iterator::next(); 17 return crnt; 18 } 19 20 bool hasNext() const { return has_next; } 21 };