leetcode 344. Reverse String

题目:

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

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

 1 public class Solution {
 2     public String reverseString(String s)  {
 3         int left = 0;
 4            int right = s.length() - 1;
 5            char[] strChar=s.toCharArray();
 6         while (left<right)
 7         {
 8             char temp=strChar[left];
 9             strChar[left]=strChar[right];
10             strChar[right]=temp;
11             left++;
12             right--;
13         }
14         return new String(strChar);
15     }
16 }

 

posted @ 2016-04-22 20:13  HelloWorld_5  阅读(428)  评论(0编辑  收藏  举报