【LeetCode】345. Reverse Vowels of a String 解题报告
生活随笔
收集整理的這篇文章主要介紹了
【LeetCode】345. Reverse Vowels of a String 解题报告
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
轉載請注明出處:http://blog.csdn.net/crazy1235/article/details/51429823
Subject
出處:https://leetcode.com/problems/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”.
Explain
該題目的意思是反轉一個字符串中的元音字母。第一個和最后一個元音字母交換,第二個和倒數第二個交換……
My Solution
首先定義一個方法去判斷一個char字符是否是元音字母。然后通過首尾兩個”指針”,當前后兩個字符都是元音字符的時候才進行交換,否則將不是元音字符的指針向前或者向后移動。
跳出條件就是start < end。
so easy~
總結
以上是生活随笔為你收集整理的【LeetCode】345. Reverse Vowels of a String 解题报告的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql date类型加一个月jdbc
- 下一篇: 视频抠像软件Imagineer Syst