# Reverse String

Write a function that takes a string as input and returns the string reversed.

**Example 1:**

```
Input: 
"hello"
Output: 
"olleh"
```

**Example 2:**

```
Input: 
"A man, a plan, a canal: Panama"
Output: 
"amanaP :lanac a ,nalp a ,nam A"
```

## Analysis

反转字符串，用two pointers很直观。

## Solution

Two Pointers

```java
public class Solution {
    public String reverseString(String s) {
        char[] chs = s.toCharArray();
        int i = 0;
        int j = s.length() - 1;
        while (i < j) {
            char temp = chs[i];
            chs[i] = chs[j];
            chs[j] = temp;
            i++;
            j--;
        }
        return new String(chs);
    }
}
```

## Reference

Six Solutions (Java) - <https://leetcode.com/problems/reverse-string/discuss/80937/JAVA-Simple-and-Clean-with-Explanations-6-Solutions>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aaronice.gitbook.io/lintcode/two_pointers/reverse-string.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
