题目描述:

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相关推荐

  1. 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 ...

  2. 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', ...

  3. Leetcode 345 Reverse Vowels of a String 字符串处理

    题意:倒置字符串中的元音字母. 用两个下标分别指向前后两个相对的元音字母,然后交换. 注意:元音字母是aeiouAEIOU. 1 class Solution { 2 public: 3 bool i ...

  4. 345. Reverse Vowels of a String - LeetCode

    Question 345. Reverse Vowels of a String Solution 思路:交换元音,第一次遍历,先把出现元音的索引位置记录下来,第二遍遍历元音的索引并替换. Java实 ...

  5. 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 ...

  6. 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 ...

  7. 【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 ...

  8. 【LeetCode】345. Reverse Vowels of a String 解题报告

    转载请注明出处:http://blog.csdn.net/crazy1235/article/details/51429823 Subject 出处:https://leetcode.com/prob ...

  9. 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', ' ...

最新文章

  1. 面试题热个身:5 亿整数的大文件,来排个序?
  2. 华为性能服务器,服务器 性能
  3. 使用mintty(_如何使用Mintty改善Cygwin控制台
  4. 【UOJ574】多线程计算【二元二项式反演】【定积分】【矩阵】【NTT 卷积】
  5. 入门云数据库Redis,满足你的高读写性能场景需求
  6. 漫谈边缘计算(一):边缘计算是大势所趋
  7. 自动填写html文本框的值,网页自动填表——文本输入框及多行文本输入框
  8. matlab连接段端子怎么画,matlab在电路仿真PPT课件
  9. thinkphp5 TP5 两表关联查询
  10. matlab中画花瓣,matlab花瓣图的编程原理是什么,向天下大侠求解!!!!给力的? 爱问知识人...
  11. window进行resize的时候ie假死(jquery插件处理)
  12. Vue若依管理系统-实现管理员配置首页计数框/折线图
  13. burg算法 matlab,基于burg算法的谱估计研究及其matlab实现.doc
  14. Python使用PIL工具、ImageDraw函数在图像上根据坐标点依次连线画矩形框,可画选择倾斜的框和折线
  15. java set region_Java Region.setJurisdiction方法代碼示例
  16. 【web3.0设计】区块链如何解决真实交易的信用问题?
  17. CSP-J 2020 入门组/普及组
  18. 杰奇cms mysql查询_杰奇cms自动推送链接插件使用方式
  19. STM32变频器 源程序是经批量验证过的原始代码,仅支持VF控制,C语言实现,完全开源,Keil uVision4编译无错误
  20. 苹果ll是什么版本_新的iPad Pro和旧版本有什么区别?苹果背后的策略是什么?...

热门文章

  1. 用一个文件,实现迷你 Web 框架(建议收藏)
  2. 前端实现搜索关键字高亮功能:
  3. 第一章网络介绍计算题及其解析[计算机网络]
  4. 520表白攻略 程序员必要的相亲准备 最近你相亲表白了嘛
  5. Android 模拟器显示不全的解决方案
  6. 如何开通公众号留言功能?
  7. Ubuntu server 16.04 修改IP地址
  8. 赵小楼《天道》《遥远的救世主》解读(1)怎么评价《遥远的救世主》《天幕红尘》这两本书和《天道》这部电视剧?
  9. 大饼震荡不变,新平台搭建?
  10. 手动在电脑桌面制作关机/重启图标并添加到任务栏