码迷,mamicode.com
首页 > 其他好文 > 详细

344. Reverse String

时间:2017-10-16 23:19:57      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:code   pre   toc   ring   char   function   []   har   含义   

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

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

题目含义:翻转字符串

 

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

 

344. Reverse String

标签:code   pre   toc   ring   char   function   []   har   含义   

原文地址:http://www.cnblogs.com/wzj4858/p/7679097.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!