Python [Leetcode 345]Reverse Vowels of a String
题目描述:
Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
Given s = "hello", return "holle".
Example 2:
Given s = "leetcode", return "leotcede".
Note:
The vowels does not include the letter "y".
解题思路:
设置两个指针,分别从前往后与从后往前移动
代码如下:
class Solution(object):def reverseVowels(self, s):""":type s: str:rtype: str"""vowels = set(list('aeiouAEIOU'))s = list(s)start = 0end = len(s) - 1while start <= end:if s[start] in vowels and s[end] in vowels :s[start], s[end] = s[end], s[start]start += 1end -= 1else:if s[start] not in vowels:start += 1if s[end] not in vowels:end -= 1return ''.join(s)
转载于:https://www.cnblogs.com/zihaowang/p/5716755.html
Python [Leetcode 345]Reverse Vowels of a String相关推荐
- LeetCode 345. Reverse Vowels of a String
题目: Write a function that takes a string as input and reverse only the vowels of a string. Example 1 ...
- Leetcode 345: Reverse Vowels of a String
问题描述: Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', ...
- Leetcode 345 Reverse Vowels of a String 字符串处理
题意:倒置字符串中的元音字母. 用两个下标分别指向前后两个相对的元音字母,然后交换. 注意:元音字母是aeiouAEIOU. 1 class Solution { 2 public: 3 bool i ...
- 345. Reverse Vowels of a String - LeetCode
Question 345. Reverse Vowels of a String Solution 思路:交换元音,第一次遍历,先把出现元音的索引位置记录下来,第二遍遍历元音的索引并替换. Java实 ...
- 345. Reverse Vowels of a String(python+cpp)
题目: Write a function that takes a string as input and reverse only the vowels of a string. Example 1 ...
- LeetCode:345. Reverse Vowels of a String
051103 题目 Write a function that takes a string as input and reverse only the vowels of a string. Exa ...
- 【LeetCode】345. Reverse Vowels of a String 解题小结
题目: Write a function that takes a string as input and reverse only the vowels of a string. Example 1 ...
- 【LeetCode】345. Reverse Vowels of a String 解题报告
转载请注明出处:http://blog.csdn.net/crazy1235/article/details/51429823 Subject 出处:https://leetcode.com/prob ...
- 345. Reverse Vowels of a String
题目: Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', ' ...
最新文章
- 面试题热个身:5 亿整数的大文件,来排个序?
- 华为性能服务器,服务器 性能
- 使用mintty(_如何使用Mintty改善Cygwin控制台
- 【UOJ574】多线程计算【二元二项式反演】【定积分】【矩阵】【NTT 卷积】
- 入门云数据库Redis,满足你的高读写性能场景需求
- 漫谈边缘计算(一):边缘计算是大势所趋
- 自动填写html文本框的值,网页自动填表——文本输入框及多行文本输入框
- matlab连接段端子怎么画,matlab在电路仿真PPT课件
- thinkphp5 TP5 两表关联查询
- matlab中画花瓣,matlab花瓣图的编程原理是什么,向天下大侠求解!!!!给力的? 爱问知识人...
- window进行resize的时候ie假死(jquery插件处理)
- Vue若依管理系统-实现管理员配置首页计数框/折线图
- burg算法 matlab,基于burg算法的谱估计研究及其matlab实现.doc
- Python使用PIL工具、ImageDraw函数在图像上根据坐标点依次连线画矩形框,可画选择倾斜的框和折线
- java set region_Java Region.setJurisdiction方法代碼示例
- 【web3.0设计】区块链如何解决真实交易的信用问题?
- CSP-J 2020 入门组/普及组
- 杰奇cms mysql查询_杰奇cms自动推送链接插件使用方式
- STM32变频器 源程序是经批量验证过的原始代码,仅支持VF控制,C语言实现,完全开源,Keil uVision4编译无错误
- 苹果ll是什么版本_新的iPad Pro和旧版本有什么区别?苹果背后的策略是什么?...