Skip to content

Commit 33b20ba

Browse files
committed
reverse string
1 parent b31037e commit 33b20ba

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Day4: reverse string

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Reverse String
2+
3+
Write a function that reverses a string. The input string is given as an array of characters char[].
4+
5+
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
6+
7+
You may assume all the characters consist of printable ascii characters.
8+
9+
10+
11+
Example 1:
12+
13+
Input: ["h","e","l","l","o"]
14+
Output: ["o","l","l","e","h"]
15+
16+
Example 2:
17+
18+
Input: ["H","a","n","n","a","h"]
19+
Output: ["h","a","n","n","a","H"]
20+
21+

day4:solution.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution(object):
2+
def reverseString(self, s):
3+
"""
4+
:type s: List[str]
5+
:rtype: None Do not return anything, modify s in-place instead.
6+
"""
7+
return s.reverse()

0 commit comments

Comments
 (0)