# 344. Reverse String

## 題目原文

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

#### Example 1:

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

#### &#x20;Example 2:

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

## **解題思路**

{% hint style="info" %}

1. 第一個字元與最後一個字元交換。
2. 第二個字元與倒數第二個字元交換。
3. 以此類推。
   {% endhint %}

## 程式解答

```cpp
class Solution 
{
public:
    string reverseString(string s) 
    {
        int size = s.length();
    
        for (int i = 0; i < size / 2; i++)
        {
            char temp;
            
            temp = s[i];
            s[i] = s[size - 1 - i];
            s[size - 1 - i] = temp; 
        }
        return s;
    }
};
```


---

# 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://stanley7342.gitbook.io/programming/leetcode/344.-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.
