[LeetCode&Python] Problem 917. Reverse Only Letters
Given a string S, return the "reversed" string where all characters that are not a letter stay in the same place, and all letters reverse their positions.
Example 1:
Input: "ab-cd"
Output: "dc-ba"
Example 2:
Input: "a-bC-dEf-ghIj"
Output: "j-Ih-gfE-dCba"
Example 3:
Input: "Test1ng-Leet=code-Q!"
Output: "Qedo1ct-eeLg=ntse-T!"
Note:
S.length <= 10033 <= S[i].ASCIIcode <= 122Sdoesn't contain\or"
class Solution:
def reverseOnlyLetters(self, S):
"""
:type S: str
:rtype: str
""" n=len(S)
s=list(S)
i=0
j=n-1
while i<j:
while i<j and not s[i].isalpha():i+=1
while i<j and not s[j].isalpha():j-=1
s[i],s[j]=s[j],s[i]
i+=1
j-=1
return ''.join(s)
[LeetCode&Python] Problem 917. Reverse Only Letters的更多相关文章
- [LeetCode&Python] Problem 541. Reverse String II
Given a string and an integer k, you need to reverse the first k characters for every 2k characters ...
- [LeetCode&Python] Problem 557. Reverse Words in a String III
Given a string, you need to reverse the order of characters in each word within a sentence while sti ...
- [LeetCode&Python] Problem 206. Reverse Linked List
Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4-> ...
- 【Leetcode_easy】917. Reverse Only Letters
problem 917. Reverse Only Letters solution: class Solution { public: string reverseOnlyLetters(strin ...
- 【LeetCode】917. Reverse Only Letters 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 栈 单指针 双指针 日期 题目地址: https:/ ...
- [LeetCode] 917. Reverse Only Letters 只翻转字母
Given a string S, return the "reversed" string where all characters that are not a letter ...
- LeetCode 917 Reverse Only Letters 解题报告
题目要求 Given a string S, return the "reversed" string where all characters that are not a le ...
- #Leetcode# 917. Reverse Only Letters
https://leetcode.com/problems/reverse-only-letters/ Given a string S, return the "reversed" ...
- 【leetcode】917. Reverse Only Letters(双指针)
Given a string s, reverse the string according to the following rules: All the characters that are n ...
随机推荐
- Qt4_WebKit_例子
1. 安装包:qt-opensource-windows-x86-vs2010-4.8.6.exe Qt4已经编译好的文件:E:\ZC_software_installDir\Qt_4.8.6\dem ...
- [源][osg][osgBullet]osgBullet例子介绍
1.BasicDemo 基本样例 一个小玩具飞机坠落,一个立方体盒子在转圈 2.centerofmass 质心 3.collision 碰撞检测 这里有一个大神自己改的例子: http://blog. ...
- 《剑指offer》第四十题(最小的k个数)
// 面试题40:最小的k个数 // 题目:输入n个整数,找出其中最小的k个数.例如输入4.5.1.6.2.7.3.8 // 这8个数字,则最小的4个数字是1.2.3.4. #include < ...
- Android仿QQ微信开场导航以及登陆界面
相信大家对于微信等社交应用的UI界面已经都很熟悉了,该UI最值得借鉴的莫过于第一次使用的时候一些列产品介绍的图片,可以左右滑动浏览,最后 进入应用,这一效果适用于多种项目中,相信今后开发应用一定会用得 ...
- 手把手教你开发BLE数据透传应用程序
如何开发BLE数据透传应用程序?什么是BLE service和characteristic?如何开发自己的service和characteristic?如何区分ATT和GATT?有没有什么工具可以对B ...
- Observable类API
包java.util 类 Observable public class Observable extends Object 此类表示模型视图范例中的 observable 对象,或者说“数据”.可将 ...
- 免费下载知网文献的方法 | sci-hub免费下载SCI论文方法
部分方法参考自在家里如何免费使用中国知网? - 大学生 - 知乎的回答,已注明出处. 知网文献下载:idata中国知网 idata中国知网网址:idata中国知网 https://www.cn-ki. ...
- English trip -- Review Unit5 Around town 在城市
restaurant 餐厅 supermarket 超市 shoping mall 购物中心 drugstore 药店 hospital 医院 laundromat 洗衣店 moive threat ...
- 4-1 contag_tag:返回HTMLtag.
jquery已经过时,做一遍,了解其他知识点. contag_tag(name, content_or_options_with_block = nil, options = nil, &bl ...
- IIS Web 服务器/ASP.NET 运行原理基本知识概念整理
前言: 记录 IIS 相关的笔记还是从公司笔试考核题开始的,问 Application Pool 与 AppDomain 的区别? 促使我对进程池进了知识的学习,所以记录一下学习 ...