【Leetcode】Reverse String(easy)
2016-05-19 15:27
246 查看
Question
Write a function that takes a string as input and returns the string reversed.Example:
Given s = “hello”, return “olleh”.
Code
#include<iostream> #include<string> using namespace std; class Solution { public: string reverseString(string s) { char temp;//临时变量 for (int i = 0; i < s.length() / 2; i++) { temp = s[i]; s[i] = s[s.length() - 1 - i]; s[s.length() - 1 - i] = temp; } return s; } }; int main() { Solution so; string s = { "hello" }; cout << so.reverseString(s) << endl;; system("pause"); return 0; }
相关文章推荐
- 交互式和非交互式shell、登录和非登录shell之间的区别
- iOS下载数据-断点续传
- 在android listview中使用editText无法获取焦点和输入窗
- elipse new class add comments
- 详解Linux下安装配置Nginx
- JAVA基础之HashMap源码(JDK 1.8)
- Dijkstra算法
- keepalive配置文件详解
- ButterKnife
- 测试
- Sql server 2008数据库误删的恢复(利用日志和一个完整备份)
- 如何提高redmine的访问速度
- 寻找水王
- 课堂作业
- 第一年
- 用一张图解释RxJava中的线程控制
- 深入理解MVC中的时间js格式化
- qt QPrint
- java随机数
- [转]学习新东西的唯一方法