Reverse by Hand
Reversing a string looks simple, but it is a great way to practice indexes and loops. The function reverse_string receives a string s and returns it in reverse order. Do not use shortcuts like the slice s[::-1] or the reversed function; implement the reversal with a loop or two pointers.
Примеры
Ввод
"hello"Вывод
"olleh"Ввод
""Вывод
""Ввод
"a"Вывод
"a"Нужно реализовать
def reverse_string(s: str) -> str:
Теги
stringstwo-pointers
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign inVisible tests
1
Input
"hello"Expected
"olleh"2
Input
""Expected
""3
Input
"a"Expected
"a"4
Input
"Avito"Expected
"otivA"5
Input
"12321"Expected
"12321"6
Input
"abc"Expected
"cba"Focus radio
Paused · SomaFM · Fluid