344. Reverse String Java Solutions
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
Subscribe to see which companies asked this question
1 public class Solution { 2 public String reverseString(String s) { 3 if(s == null || s.length() <=1) return s; 4 StringBuffer res = new StringBuffer(s.length()); 5 for(int i = s.length()-1;i >=0 ;i--){ 6 res.append(s.charAt(i)); 7 } 8 return res.toString(); 9 } 10 }