541. Reverse String II
来源:互联网 发布:张辛苑自己的淘宝店 编辑:程序博客网 时间:2024/04/30 15:17
Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and left the other as original.
Example:
Input: s = "abcdefg", k = 2Output: "bacdfeg
code:
class Solution(object): def reverseStr(self, s, k): """ :type s: str :type k: int :rtype: str """ s=list(s) for i in xrange(0,len(s),2*k): s[i:i+k]=s[i:i+k][::-1] return "".join(s)
0 0
- 541. Reverse String II
- 541. Reverse String II
- 541. Reverse String II
- 541. Reverse String II
- 541. Reverse String II
- 541. Reverse String II
- 541. Reverse String II
- 541. Reverse String II
- 541. Reverse String II
- 541. Reverse String II
- 541. Reverse String II
- 541. Reverse String II
- 541. Reverse String II
- 541. Reverse String II
- 541. Reverse String II
- String:541. Reverse String II
- leetcode 541. Reverse String II
- Leetcode-541. Reverse String II
- 微信公众平台发布小程序数据助手 可查看运营数据
- java安全架构____Hmac秘钥加密自己的摘要数据
- 【搜索】洛谷 P1473 零的数列 Zero Sum
- getopt()函数(分析命令行参数)
- 牛客之统计n个单词中有多少种循环单词
- 541. Reverse String II
- 创建一个简单的WCF
- [Java面试三]JavaWeb基础知识总结.
- mysql c++ 访问 soci
- 【DP】洛谷 P1474 货币系统 Money Systems
- ConcurrentLinkedHashMap 这货竟然没有链表的属性
- 找实习
- Spark性能优化:数据倾斜调优
- UE4 c++加密 (附带读取和保存文件)