mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-05 00:48:03 +00:00
Update set of stacks challenge solution (#110)
Add is_empty() method, remove extra linebreak.
This commit is contained in:
@@ -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"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user