leetcode 344 Reverse String || leetcode 345 Reverse Vowels of a String

leetcode Reverse String

Write a function that takes a string as input and returns the string reversed.

Example:
Given s = “hello”, return “olleh”.

题目地址:leetcode Reverse String

题意:给定一个字符串,让你逆序

思路:

双指针,直接置换

C++

也可以直接用swap

 

Python 直接oneline

 

 


 

leetcode  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”.

题目地址:leetcode Reverse Vowels of a String

题意:给定一个字符串,把它的所有元音字母逆序

思路:同样双指针,遇到元音(a,e,i,o,u 注意大小写)就停下来

C++

 

 

PS:本来不想写题解的,昨天那题太水了= =不过今天又出了一道类似的水题,就一起写了吧

 

本题是leetcode 344 Reverse String 和 345 Reverse Vowels of a String  题解,

更多题解可以查看:https://www.hrwhisper.me/leetcode-algorithm-solution/

本博客若无特殊说明则由 hrwhisper 原创发布
转载请点名出处:细语呢喃 > leetcode 344 Reverse String || leetcode 345 Reverse Vowels of a String
本文地址:https://www.hrwhisper.me/leetcode-345-reverse-vowels-string-leetcode-344-reverse-string/

您的支持将鼓励我继续创作!

Leetcode , , , . permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *