
Write a function that reverses a string. The input string is given as an array of characters char[].
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
You may assume all the characters consist of printable ascii characters.
Example 1:
1 |
Input: ["h","e","l","l","o"] |
Example 2:
1 |
Input: ["H","a","n","n","a","h"] |
在不占用额外内存的情况下,翻转数组.
实现
- Python
1 |
def (self, s) -> None: |
讨论区其他答案
- java
1 |
public class Solution { |




近期评论