344 Reverse String 反转字符串
请编写一个函数,其功能是将输入的字符串反转过来。
示例:
输入:s = "hello"
返回:"olleh"
详见:https://leetcode.com/problems/reverse-string/description/
C++:
class Solution {
public:
string reverseString(string s) {
int n=s.size();
if(n==0||s.empty())
{
return "";
}
int left=0,right=n-1;
while(left<right)
{
char tmp=s[left];
s[left]=s[right];
s[right]=tmp;
++left;
--right;
}
return s;
}
};
344 Reverse String 反转字符串的更多相关文章
- LeetCode 344. Reverse String(反转字符串)
题目描述 LeetCode 344. 反转字符串 请编写一个函数,其功能是将输入的字符串反转过来. 示例 输入: s = "hello" 返回: "olleh" ...
- Leetcode 344:Reverse String 反转字符串(python、java)
Leetcode 344:Reverse String 反转字符串 公众号:爱写bug Write a function that reverses a string. The input strin ...
- [LeetCode] 344. Reverse String 翻转字符串
Write a function that reverses a string. The input string is given as an array of characters char[]. ...
- Leetcode#344. Reverse String(反转字符串)
题目描述 编写一个函数,其作用是将输入的字符串反转过来. 示例 1: 输入: "hello" 输出: "olleh" 示例 2: 输入: "A man ...
- 344. Reverse String(C++)
344. Reverse String Write a function that takes a string as input and returns the string reversed. E ...
- [LeetCode] 344 Reverse String && 541 Reverse String II
原题地址: 344 Reverse String: https://leetcode.com/problems/reverse-string/description/ 541 Reverse Stri ...
- leetcode 344. Reverse String 、541. Reverse String II 、796. Rotate String
344. Reverse String 最基础的旋转字符串 class Solution { public: void reverseString(vector<char>& s) ...
- LeetCode Javascript实现 344. Reverse String 292. Nim Game 371. Sum of Two Integers
344. Reverse String /** * @param {string} s * @return {string} */ var reverseString = function(s) { ...
- 【leetcode】344. Reverse String
problem 344. Reverse String solution: class Solution { public: void reverseString(vector<char> ...
随机推荐
- scanf与getchar
如下: 5 5 R R R R R R R R R R R R R R R R R R R R R R R R R 只允许用scanf,如何写读取函数. 由于 ...
- dp专题备忘录
hdu 1024:基础dp题 hdu 1029:主元素问题,很快的解法,计数器 hdu 1069:LIS hdu 1074:数位dp,数位dp基础 hdu 1257:简单LIS,要仔细分析为什么是求最 ...
- java 中序列化(Serializable)
18年5月份,在毕业快一年的时候,我终于把自己从研发助理偏向行政打杂,偶尔写一些前端代码的处境,回归到了初衷-安安静静写前后端代码的小小程序员~过程中的心酸也就不在这里吐啦,毕竟我是小太阳,永不熄灭的 ...
- [luoguP1941] 飞扬的小鸟(DP)
传送门 动归,用f[i][j]表示到达第I列高度为j时最少需要飞的次数,容易想到最裸的转移: f[i][j]=min(min(f[i-1][j-up[i-1]*k]+k),f[i-1][j+down[ ...
- RCC 2014 Warmup (Div. 2) 蛋疼解题总结
A. Elimination time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Sql语句中关于如何在like '%?%'中给?赋值
做模糊查询用户的时候,如果 String sql="select * from users where name like %?%"; String[] param={userna ...
- Memory+SLES 11/12 OS Tuning & Optimization
https://www.suse.com/documentation/sles11/book_sle_tuning/data/sec_util_memory.html SLES 11/12 OS Tu ...
- PostGIS学习相关术语
POI 兴趣点(英语:point of interest,通常缩写成POI)乃是电子地图上的某个地标.景点,用以标示出该地所代表的政府部门.各行各业之商业机构(加油站.百货公司.超市.餐厅.酒店.便利 ...
- Ubuntu 16.04通过Unity Tweak Tool实现点击图标最小化
1.通过Ubuntu软件中心安装Unity Tweak Tool 2.设置
- Android GIS开发系列-- 入门季(1) 起点
前言 这个系列,待最终完成更新,大家体谅点,第一版本全部是参考的网络教程,最近会逐步的细化更新为可以直接使用的情况. 本系列的开发基于AS ( Android Studio ), 和ArcGIS 的 ...