首页 > 其他 > 详细

Leetcode 344. Reverse String

时间:2016-07-22 07:42:09      阅读:324      评论:0      收藏:0      [点我收藏+]

344. Reverse String 

  • Total Accepted: 56722
  • Total Submissions: 96534
  • Difficulty: Easy

 

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

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

 

思路:字符串反转,交换s[i]和s[s.size()-1-i]

 

 

代码:

 1 class Solution {
 2 public:
 3     string reverseString(string s) {
 4         int i=0,j=s.size()-1;
 5         while(i<j){
 6             swap(s[i++],s[j--]);
 7         }
 8         return s;
 9     }
10 };

 

Leetcode 344. Reverse String

原文:http://www.cnblogs.com/Deribs4/p/5693772.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!