Reverse Vowels
生活随笔
收集整理的這篇文章主要介紹了
Reverse Vowels
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
* Write a function that takes a string as input and reverse only the vowels of a string
? ? ?* 意思就是將給定字符串中所有元音字母前后對(duì)調(diào)
? ? ?* Given s = "hello", return "holle".sannereoooo
? ? ?* 意思就是將給定字符串中所有元音字母前后對(duì)調(diào)
? ? ?* Given s = "hello", return "holle".sannereoooo
? ? ?* Given s = "linatcode", return "lenotcadi".
private string ReverseVowels2(string s){List<int> map = new List<int>(); //存儲(chǔ)字符串中所有元音字母的位置char[] chars = s.ToCharArray(); for (int i = 0; i < chars.Length; i++){if (IsVowels(chars[i]))map.Add(i);}for (int i = 0; i <= map.Count / 2 - 1; i++){char temp = chars[map[i]];chars[map[i]] = chars[map[map.Count - i - 1]];chars[map[map.Count - i - 1]] = temp;}return new string(chars);}private bool IsVowels(char c){return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U';}總結(jié)
以上是生活随笔為你收集整理的Reverse Vowels的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: scss2css vscode设置_VS
- 下一篇: Video Matting:AI视频抠图