-
Notifications
You must be signed in to change notification settings - Fork 161
/
reverse-string.md
25 lines (18 loc) · 1.21 KB
/
reverse-string.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<p>Write a function that reverses a string. The input string is given as an array of characters <code>char[]</code>.</p>
<p>Do not allocate extra space for another array, you must do this by <strong>modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a></strong> with O(1) extra memory.</p>
<p>You may assume all the characters consist of <a href="https://en.wikipedia.org/wiki/ASCII#Printable_characters" target="_blank">printable ascii characters</a>.</p>
<p> </p>
<div>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong><span id="example-input-1-1">["h","e","l","l","o"]</span>
<strong>Output: </strong><span id="example-output-1">["o","l","l","e","h"]</span>
</pre>
<div>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong><span id="example-input-2-1">["H","a","n","n","a","h"]</span>
<strong>Output: </strong><span id="example-output-2">["h","a","n","n","a","H"]</span>
</pre>
</div>
</div>