/*
* @lc app=leetcode.cn id=344 lang=c
*
* [344] 反转字符串
*
* https://leetcode-cn.com/problems/reverse-string/description/
*
* algorithms
* Easy (65.20%)
* Total Accepted: 39.8K
* Total Submissions: 61.1K
* Testcase Example: '["h","e","l","l","o"]'
*
* 编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组 char[] 的形式给出。
*
* 不要给另外的数组分配额外的空间,你必须原地修改输入数组、使用 O(1) 的额外空间解决这一问题。
*
* 你可以假设数组中的所有字符都是 ASCII 码表中的可打印字符。
*
*
*
* 示例 1:
*
* 输入:["h","e","l","l","o"]
* 输出:["o","l","l","e","h"]
*
*
* 示例 2:
*
* 输入:["H","a","n","n","a","h"]
* 输出:["h","a","n","n","a","H"]
*
*/
void reverseString(char* s, int sSize) {
int i,j=sSize-;
char temp;
for(i=;i<j;i++){
temp = s[i];
s[i] = s[j];
s[j] = temp;
j--;
}
return s;
}

很简单,两头往中间来回替换即可。

python更是一个函数就搞定(虽然效率低了点。。)

#
# @lc app=leetcode.cn id=344 lang=python3
#
# [344] 反转字符串
#
# https://leetcode-cn.com/problems/reverse-string/description/
#
# algorithms
# Easy (65.20%)
# Total Accepted: 39.8K
# Total Submissions: 61.1K
# Testcase Example: '["h","e","l","l","o"]'
#
# 编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组 char[] 的形式给出。
#
# 不要给另外的数组分配额外的空间,你必须原地修改输入数组、使用 O(1) 的额外空间解决这一问题。
#
# 你可以假设数组中的所有字符都是 ASCII 码表中的可打印字符。
#
#
#
# 示例 1:
#
# 输入:["h","e","l","l","o"]
# 输出:["o","l","l","e","h"]
#
#
# 示例 2:
#
# 输入:["H","a","n","n","a","h"]
# 输出:["h","a","n","n","a","H"]
#
#
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
s.reverse()

Leecode刷题之旅-C语言/python-344反转字符串的更多相关文章

  1. Leecode刷题之旅-C语言/python-7.整数反转

    /* * @lc app=leetcode.cn id=7 lang=c * * [7] 整数反转 * * https://leetcode-cn.com/problems/reverse-integ ...

  2. Leecode刷题之旅-C语言/python-1.两数之和

    开学后忙的焦头烂额(懒得很),正式开始刷leecode的题目了. 想了想c语言是最最基础的语言,虽然有很多其他语言很简单,有更多的函数可以用,但c语言能煅炼下自己的思考能力.python则是最流行的语 ...

  3. Leecode刷题之旅-C语言/python-387 字符串中的第一个唯一字符

    /* * @lc app=leetcode.cn id=387 lang=c * * [387] 字符串中的第一个唯一字符 * * https://leetcode-cn.com/problems/f ...

  4. Leecode刷题之旅-C语言/python-28.实现strstr()

    /* * @lc app=leetcode.cn id=28 lang=c * * [28] 实现strStr() * * https://leetcode-cn.com/problems/imple ...

  5. Leecode刷题之旅-C语言/python-434 字符串中的单词数

    /* * @lc app=leetcode.cn id=434 lang=c * * [434] 字符串中的单词数 * * https://leetcode-cn.com/problems/numbe ...

  6. Leecode刷题之旅-C语言/python-326 3的幂

    /* * @lc app=leetcode.cn id=326 lang=c * * [326] 3的幂 * * https://leetcode-cn.com/problems/power-of-t ...

  7. Leecode刷题之旅-C语言/python-263丑数

    /* * @lc app=leetcode.cn id=263 lang=c * * [263] 丑数 * * https://leetcode-cn.com/problems/ugly-number ...

  8. Leecode刷题之旅-C语言/python-383赎金信

    /* * @lc app=leetcode.cn id=383 lang=c * * [383] 赎金信 * * https://leetcode-cn.com/problems/ransom-not ...

  9. Leecode刷题之旅-C语言/python-349两整数之和

    /* * @lc app=leetcode.cn id=371 lang=c * * [371] 两整数之和 * * https://leetcode-cn.com/problems/sum-of-t ...

随机推荐

  1. 【Leetcode】【Medium】Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  2. Toad for MySQL 7.3 Freeware异常 2017-01-09 15:14 115人阅读 评论(0) 收藏

    打开Toad出现如下异常信息: 解决办法: 重装.NET Framework4.0

  3. selenium+python 数据驱动-txt篇

    #循环读取txt文件中的数据,可以作为用户名,密码等使用from selenium import webdriver #创建两个列表user=[]pwd=[]f=open(r'C:\bbs\data\ ...

  4. 模式:模版、样式;属于分类、识别的范围;分类、归类的标准-How are patterns obtained?

    模式及套路 模式:模版.样式:属于分类.识别的范围. How are patterns obtained? Through : re-use, classification and finally a ...

  5. Centos 7 安装Anaconda3

    1.首先下载地址: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ 使用清华镜像下载速度快 2.安装 bash Anaconda3-5.1 ...

  6. Linux实用指令(2)

    cat指令     cat 查看文件内容,只读的方式 • 基本语法     cat [选项] 要查看的文件 • 常用选项     -n :显示行号 • 应用实例   注意:cat 只能浏览文件,而不能 ...

  7. Page Object设计模式(项目整体结构)

    1. 什么是框架 1.1 定义: 框架(Framework)是整个或部分系统的可重用设计,表现为一组抽象构件(类)及构件(类)实例间交互的方法. 1.2 为什么要搭建自动化测试框架 自动化测试的开发, ...

  8. RabbitMQ之五种消息模型

    首先什么是MQ MQ全称是Message Queue,即消息对列!消息队列是典型的:生产者.消费者模型.生产者不断向消息队列中生产消息,消费者不断的从队列中获取消息.因为消息的生产和消费都是异步的,而 ...

  9. java中构造器的调用顺序

    在编程的过程中,我们经常会遇到多个类的继承问题,那么多个类的构造器是按照什么顺序调用的呢? 先看一段代码: public class Meal { public Meal() { System.out ...

  10. C#串口通讯

    本文提供一个用C#实现串口通讯实例,亲自编写,亲测可用! 开发环境:VS2008+.net FrameWork3.5(实际上2.0应该也可以) 第一步 创建一个WinForm窗体,拉入一些界面元素 重 ...