> For the complete documentation index, see [llms.txt](https://anand-aryan.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://anand-aryan.gitbook.io/leetcode/344.-reverse-string.md).

# 344. Reverse String

Reverse String

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

Example: Given s = "hello", return "olleh".

## Solution <a href="#solution" id="solution"></a>

```java
public class Solution {
  public String reverseString(String s) {
        if (s == null || s.length() == 0 || s.length() == 1) {
            return s;
        }

        StringBuffer sb = new StringBuffer();
        for(int i = s.length() - 1; i >= 0; i --) {
            sb.append(s.charAt(i));
        }

        return sb.toString();
    }
}
```
