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> ...
随机推荐
- 统计nginx日志里每五分钟的访问量
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Random_lee import time import os import re cla ...
- java---括号匹配
import java.util.HashMap;import java.util.LinkedList;import java.util.Map; /* *括号匹配 * 1.用栈实现,如果读取字符为 ...
- POJ 3468 线段树区间修改查询(Java,c++实现)
POJ 3468 (Java,c++实现) Java import java.io.*; import java.util.*; public class Main { static int n, m ...
- jmeter 性能测试
1. Ramp-up Period(in seconds)代表多长时间内启动所有线程 2. Aggregate Report Samples:总共发给服务器的请求数量 Average:单个请求的平均响 ...
- EasyUI Datagrid的简单使用
此前同样写过EasyUI Datagrid的demo,好记性不如烂笔头,何况记性也不是那么好,赶紧记录一下.照搬上一篇EasyUI Tree的格式. 实现效果:获取数据库表的数据,在EasyUI Da ...
- NYOJ 832 合并游戏
合并游戏 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 大家都知道Yougth除了热爱编程之外,他还有一个爱好就是喜欢玩.某天在河边玩耍的时候,他发现了一种神奇的石 ...
- Tensorflow word2vec+manage experiments
Lecture note 5: word2vec + manage experiments Word2vec Most of you are probably already familiar wit ...
- spoj 375 树链剖分模板
/* 只是一道树链刨分的入门题,作为模板用. */ #include<stdio.h> #include<string.h> #include<iostream> ...
- 页面加载即执行JQuery的三种方法
[1]$(function( ){ }): $(function(){ $("#name").click(function(){ //adding your code here } ...
- [USACO06FEB]数字三角形
题目描述 FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N ...