leetcode344题 题解 翻译 C语言版 Python版
来源:互联网 发布:java按层次遍历二叉树 编辑:程序博客网 时间:2024/06/05 05:24
344. Reverse String
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
344.逆转字符串
写一个函数,功能是输入一个字符串然后输入其逆序后的结果
例如:
给定s="hello", 返回 "olleh"。
思路:用c的话分配一个len+1的内存,然后倒序填入到这块内存中即可。python的话比较简单,直接用切片操作获取逆序字符串即可。
char* reverseString(char* s) { int len = strlen(s); char* p = (char*)malloc(len+1); for (int i = len-1; i >= 0; i--){ p[len-1-i] = s[i]; } p[len] = 0; return p;}
class Solution(object): def reverseString(self, s): """ :type s: str :rtype: str """ return s[::-1]
0 0
- leetcode344题 题解 翻译 C语言版 Python版
- leetcode292题 题解 翻译 C语言版 Python版
- leetcode258题 题解 翻译 C语言版 Python版
- leetcode104题 题解 翻译 C语言版 Python版
- leetcode237题 题解 翻译 C语言版 Python版
- leetcode226题 题解 翻译 C语言版 Python版
- leetcode283题 题解 翻译 C语言版 Python版
- leetcode100题 题解 翻译 C语言版 Python版
- leetcode242题 题解 翻译 C语言版 Python版
- leetcode171题 题解 翻译 C语言版 Python版
- leetcode235题 题解 翻译 C语言版 Python版
- leetcode206题 题解 翻译 C语言版 Python版
- leetcode328题 题解 翻译 C语言版 Python版
- leetcode191题 题解 翻译 C语言版 Python版
- leetcode70题 题解 翻译 C语言版 Python版
- leetcode83题 题解 翻译 C语言版 Python版
- leetcode263题 题解 翻译 C语言版 Python版
- leetcode326题 题解 翻译 C语言版 Python版
- 碰集
- MFC学习笔记——CDialog入门
- 解读Unity中的CG编写Shader系列二
- strcpy和memcpy的区别
- jbpm gpd.xml中文乱码
- leetcode344题 题解 翻译 C语言版 Python版
- RabbitMQ学习(八)之spring-amqp的重要类的认识
- 键盘退出
- Handler、Looper消息传递机制
- handle句柄
- Hadoop常用命令及常见问题
- 【Hibernate持续更新】映射组件关系
- 解读Unity中的CG编写Shader系列三
- 自动装箱、拆箱与遍历循环(Foreach循环)