/*
* @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. java Maven项目右键没有maven菜单项的解决方案!

    修改项目.project文件,确保有maven2Builder和maven2Nature2个标签: <?xml version="1.0" encoding="UT ...

  2. 在Server2012R2上导入Server2008R2的HyperV虚拟机

    Importing Windows 2008 R2 Hyper-V VM Into Windows 8.1 For the purposes of this post, let’s try and i ...

  3. PowerShell管理Azure

    PowerShell第一次连接Azure1.下载Azure SDK,安装azure powershell http://azure.microsoft.com/zh-cn/downloads/?rnd ...

  4. 设计模式:组合(Composite)模式

    设计模式:组合(Composite)模式 一.前言   关于Composite模式,其实就是组合模式,又叫部分整体模式,这个模式在我们的生活中也经常使用,比如说如果读者有使用Java的GUI编写过程序 ...

  5. python 中if-else的多种简洁的写法

    因写多了判断语句,看着短短的代码却占据来好几行,于是便搜下if-else简洁的写法,结果也是发现新大陆 4种: 第1种:__就是普通写法 a, b, c = 1, 2, 3 if a>b: c ...

  6. 微信公众号支付IOS系统能够唤起,安卓系统不能唤起的问题解决

    前言 之前系统内做过要给微信支付程序,只不过鉴于业务应用场景,大部分都是使用业务内的金币兑换产品,没有实际用到支付功能.后来运营小哥哥说他的手机不能唤起支付.于是乎我查询了一下资料,发现了这么个问题. ...

  7. 【转】Spring Boot Profile使用

    http://blog.csdn.net/he90227/article/details/52981747 摘要: spring Boot使用@Profile注解可以实现不同环境下配置参数的切换,任何 ...

  8. python-使用递归实现二分法

    在上一篇中简单介绍了递归的使用,请戳这里 .  在此篇中,主要介绍如何用递归实现二分法. 在使用二分法之前,首先要有个前提,那就是这个数组必须是有序数组.主要的思路为: ①先取出数组中的一个中间值, ...

  9. springmvc错误集锦-dubbo包含低版本的spring包,依赖的时候应该排除Caused by: java.lang.reflect.MalformedParameterizedTypeException

    dubbo 常见错误 1. Caused by: java.lang.reflect.MalformedParameterizedTypeException 启动时报错,原因是dubbo 依赖 spr ...

  10. 两种方式(xml+代码)构建SqlSessionFactory+完整实现

    首先创建类.接口.数据库: entity包下Admin类: package com.wbg.springJavaConfig.entity; public class Admin { private ...