mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Update reverse string challenge (#113)
Update input check logic to check for an empty but not None entry.
This commit is contained in:
parent
aa4c8ae5b4
commit
c6677586d3
|
@ -97,8 +97,8 @@
|
|||
"class ReverseString(object):\n",
|
||||
"\n",
|
||||
" def reverse(self, chars):\n",
|
||||
" if chars is None:\n",
|
||||
" return None\n",
|
||||
" if chars is None or not chars:\n",
|
||||
" return chars\n",
|
||||
" size = len(chars)\n",
|
||||
" for i in range(size//2):\n",
|
||||
" chars[i], chars[size-1-i] = \\\n",
|
||||
|
@ -126,13 +126,13 @@
|
|||
"class ReverseStringAlt(object):\n",
|
||||
"\n",
|
||||
" def reverse_string_alt(string):\n",
|
||||
" if string is None:\n",
|
||||
" return None\n",
|
||||
" if string is None or not string:\n",
|
||||
" return string\n",
|
||||
" return string[::-1]\n",
|
||||
"\n",
|
||||
" def reverse_string_alt2(string):\n",
|
||||
" if string is None:\n",
|
||||
" return None\n",
|
||||
" if string is None or not string:\n",
|
||||
" return string\n",
|
||||
" return ''.join(reversed(string))"
|
||||
]
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue
Block a user