344. Reverse String
Difficulty:?Easy
Write a function that takes a string as input and returns the string reversed.
??? Example:
??? Given s = "hello", return "olleh".
?
?
public class Solution { public String reverseString(String s) { char[] sArray = s.toCharArray(); int length = sArray.length; for (int i = 0; i < length/2; i ++) { char temp = sArray[i]; int position = length - 1 - i; sArray[i] = sArray[position]; sArray[position] = temp; } return new String(sArray); } }?总觉得这个代码效率有点低,如果有更快的解决方法,欢迎交流啊。
344. Reverse String LeetCode 解题
原文:http://rayfuxk.iteye.com/blog/2302665