mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Update set of stacks challenge solution (#110)
Add is_empty() method, remove extra linebreak.
This commit is contained in:
parent
a7fc172004
commit
12b58ccf9b
|
@ -136,6 +136,9 @@
|
||||||
" def is_full(self):\n",
|
" def is_full(self):\n",
|
||||||
" return self.num_items == self.capacity\n",
|
" return self.num_items == self.capacity\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
" def is_empty(self):\n",
|
||||||
|
" return self.num_items == 0\n",
|
||||||
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class SetOfStacks(object):\n",
|
"class SetOfStacks(object):\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -154,10 +157,9 @@
|
||||||
" if self.last_stack is None:\n",
|
" if self.last_stack is None:\n",
|
||||||
" return None\n",
|
" return None\n",
|
||||||
" data = self.last_stack.pop()\n",
|
" data = self.last_stack.pop()\n",
|
||||||
" if not self.last_stack.num_items:\n",
|
" if self.last_stack.is_empty():\n",
|
||||||
" self.stacks.pop()\n",
|
" self.stacks.pop()\n",
|
||||||
" self.last_stack = self.stacks[-1] \\\n",
|
" self.last_stack = self.stacks[-1] if self.stacks else None\n",
|
||||||
" if len(self.stacks) else None\n",
|
|
||||||
" return data"
|
" return data"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user