Update set of stacks challenge solution (#110)

Add is_empty() method, remove extra linebreak.
This commit is contained in:
Donne Martin 2016-10-29 09:10:32 -04:00 committed by GitHub
parent a7fc172004
commit 12b58ccf9b

View File

@ -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"
] ]
}, },