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

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

Subscribeto see which companies asked this question.

Hide Tags

Two Pointers

String

Hide Similar Problems

(E) Reverse Vowels of a String

(E) Reverse String II


public class Solution {
    public String reverseString(String s) {
        int length = s.length();
        char[] result = new char[length];

        for(int i=0;i<length;i++){
            result[i] = s.charAt(length-1-i);
        }
        return new String(result);
    }
}

results matching ""

    No results matching ""