Class Solution

java.lang.Object
g0301_0400.s0344_reverse_string.Solution

public class Solution extends Object
344 - Reverse String.<p>Easy</p> <p>Write a function that reverses a string. The input string is given as an array of characters <code>s</code>.</p> <p>You must do this by modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_top">in-place</a> with <code>O(1)</code> extra memory.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = [&ldquo;h&rdquo;,&ldquo;e&rdquo;,&ldquo;l&rdquo;,&ldquo;l&rdquo;,&ldquo;o&rdquo;]</p> <p><strong>Output:</strong> [&ldquo;o&rdquo;,&ldquo;l&rdquo;,&ldquo;l&rdquo;,&ldquo;e&rdquo;,&ldquo;h&rdquo;]</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = [&ldquo;H&rdquo;,&ldquo;a&rdquo;,&ldquo;n&rdquo;,&ldquo;n&rdquo;,&ldquo;a&rdquo;,&ldquo;h&rdquo;]</p> <p><strong>Output:</strong> [&ldquo;h&rdquo;,&ldquo;a&rdquo;,&ldquo;n&rdquo;,&ldquo;n&rdquo;,&ldquo;a&rdquo;,&ldquo;H&rdquo;]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 10<sup>5</sup></code></li> <li><code>s[i]</code> is a <a href="https://en.wikipedia.org/wiki/ASCII#Printable_characters" target="_top">printable ascii character</a>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • reverseString

      public void reverseString(char[] s)