leetcode submission/20160720(reverse string)
2016-07-20 15:57
267 查看
北京大雨,妈的下了一天
I choose a rather easy topic, cause' it's the first time that I code in leetcode, prior object is to test.
Topic:
Reverse String
Write
a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
/************************************************************/
My
answer:
#include
<stdio.h>
#include <string>
#include <iostream>
class Solution {
public:
string reverseString(string s) {
for (int i = 0;i<s.length()/2;++i) {
char c = s[i];
s[i] = s[s.length() - i - 1];
s[s.length() - i - 1] = c;
}
return s;
}
};
I choose a rather easy topic, cause' it's the first time that I code in leetcode, prior object is to test.
Topic:
Reverse String
Write
a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
/************************************************************/
My
answer:
#include
<stdio.h>
#include <string>
#include <iostream>
class Solution {
public:
string reverseString(string s) {
for (int i = 0;i<s.length()/2;++i) {
char c = s[i];
s[i] = s[s.length() - i - 1];
s[s.length() - i - 1] = c;
}
return s;
}
};
相关文章推荐
- 学这些课程对编程有什么用
- 图片拉伸方法
- iOS9 3DTouch 新特性之实现过程—OC版
- 常用算法
- Java之通过继承来扩展接口
- 加权随机先期检测(WRED:Weighted Random Early Detection)
- ThinkPHP - 常用的配置项
- Oracle 11g透明网关连接Sqlserver
- OnGlobalLayoutListener获得一个视图的高度
- 分拆素数和 hd 2098
- 计算机专业入门都有哪些课程
- JAVA_运算符
- 进程线程
- hdoj2098分拆素数和
- eq lq lt
- C++——string的使用
- sql中如何分割字符串
- codeforces水题100道 第四题 Codeforces Round #105 (Div. 2) A. Insomnia cure (math)
- 【mysql】用navicat连接虚拟机mysql出现错误代码(10038)
- Tomcat的Session过期处理策略