LeetCode----344. Reverse String 字符串反转
来源:互联网 发布:深圳网络推广qebang 编辑:程序博客网 时间:2024/06/07 10:12
344. Reverse String
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
设两个指针,分别指向字符串的首和尾,同时向中间移动,移动次数为字符串长度的1/2.
class Solution {public: string reverseString(string s) { if(s.size()==0||s.size()==1){ return s; } char *f,*l; f=&s[0]; l=&s[s.size()-1]; for(int i=0;i<s.size()/2;i++){ char tmp=*f; *f++=*l; *l--=tmp; } return s; }};
0 0
- LeetCode----344. Reverse String 字符串反转
- [LeetCode]344. Reverse String(反转字符串)
- leetcode 344. Reverse String 反转字符串
- 字符串反转--Leetcode Reverse String
- LeetCode Reverse String(字符串反转)
- 344. Reverse String 反转字符串
- LeetCode——344. Reverse String(字符串反转)
- [Leetcode,python] Reverse String 反转字符串
- leetcode Reverse String II 反转字符串
- Leetcode 344 Reverse String 反转字符串
- LeetCode--Reverse String 反转字符串(Python)
- leetcode 541. Reverse String II 反转字符串
- Reverse String 字符串反转
- leetcode解题之344. Reverse String & 345. Reverse Vowels of a String Java版(反转字符串)
- LeetCode Reverse Words in a String(反转字符串)
- LeetCode Reverse Words in a String(反转字符串)
- 字符串反转 reverse-words-in-a-string @LeetCode
- 【LeetCode】字符串反转函数的几个算法 Reverse String
- perl 的初次接触
- MongoDB小结30 - 聚合管道【$limit】
- socket网络编程
- find the safest road
- javascript进阶之基础篇二:对象
- LeetCode----344. Reverse String 字符串反转
- Layout布局中Button被拉伸解决方法
- 参照数据字典中的表类型生成内表对象或结构体
- KVM源代码分析2:虚拟机的创建与运行
- 160803
- android中广播的理解
- github使用方法
- 浅谈Tomcat
- VS2008--VS2013 各种版本官方下载地址