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

LeetCode:Reverse String

时间:2016-06-05 11:14:14      阅读:118      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!