首页 > 其他 > 详细

LeetCode:Reverse String

时间:2016-06-05 11:12:42      阅读:224      评论:0      收藏:0      [点我收藏+]

Reverse String




Total Accepted: 32384 Total Submissions: 55169 Difficulty: Easy

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

Hide Tags
 Two Pointers String
Hide Similar Problems
 (E) Reverse Vowels of a String
















c++ code:

class Solution {
public:
    string reverseString(string s) {
        
        int len = s.length();
        int i=0,j=len-1;
        
        while(i<j) {
            s[i] ^= s[j] ^= s[i] ^= s[j];
            i++;
            j--;
        }
        return s;
    }
};


LeetCode:Reverse String

原文:http://blog.csdn.net/itismelzp/article/details/51588257

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