mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-03 16:08:02 +00:00
Update reverse string challenge (#113)
Update input check logic to check for an empty but not None entry.
This commit is contained in:
@@ -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))"
|
||||
]
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user