LeetCode:反转字符串中的元音字母【345】

题目描述

编写一个函数,以字符串作为输入,反转该字符串中的元音字母。

示例 1:

输入: "hello"
输出: "holle"

示例 2:

输入: "leetcode"
输出: "leotcede"

说明:
元音字母不包含字母"y"。

题目分析

  所谓的做题就是把以前背下来的拿过来改一下即可。双指针碰撞模型,之前已经描述过很多次了,此处不在赘述。

  知道AEIOU是元音字母?左右指针所指向元素交换一下位置即可

Java题解

class Solution {
public String reverseVowels(String s) {
char[] arr = s.toCharArray();
int left =0;
int right =arr.length-1; while(left<right)
{
while(!isYuanYin(s.charAt(left))&&left<right)
left++;
while(!isYuanYin(s.charAt(right))&&left<right)
right--;
swap(left,right,arr);
left++;right--;
}
return new String(arr); } public boolean isYuanYin(char c)
{
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
return true;
if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U')
return true;
return false;
} public void swap(int i,int j,char[] arr)
{
char tmp = arr[i];
arr[i] =arr[j];
arr[j]=tmp;
}
}

  

LeetCode:反转字符串中的元音字母【345】的更多相关文章

  1. Java实现 LeetCode 345 反转字符串中的元音字母

    345. 反转字符串中的元音字母 编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "holle" 示例 ...

  2. Leetcode 345. 反转字符串中的元音字母 By Python

    编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "holle" 示例 2: 输入: "leet ...

  3. 【leetcode 简单】 第八十三题 反转字符串中的元音字母

    编写一个函数,以字符串作为输入,反转该字符串中的元音字母. 示例 1: 输入: "hello" 输出: "holle" 示例 2: 输入: "leet ...

  4. 345 Reverse Vowels of a String 反转字符串中的元音字母

    编写一个函数,以字符串作为输入,反转该字符串中的元音字母.示例 1:给定 s = "hello", 返回 "holle".示例 2:给定 s = "l ...

  5. [Swift]LeetCode345. 反转字符串中的元音字母 | Reverse Vowels of a String

    Write a function that takes a string as input and reverse only the vowels of a string. Example 1: In ...

  6. leetCode题解之反转字符串中的元音字母

    1.问题描述 Reverse Vowels of a String Write a function that takes a string as input and reverse only the ...

  7. Python实现 "反转字符串中的元音字母" 的方法

    #coding=utf- def reverseVowels(s): """ :type s: str :rtype: str """ sS ...

  8. C#LeetCode刷题之#345-反转字符串中的元音字母​​​​​​​(Reverse Vowels of a String)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3935 访问. 编写一个函数,以字符串作为输入,反转该字符串中的元 ...

  9. [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:Giv ...

随机推荐

  1. C#操作消息列队

    首先安装消息队列MSMQ,在“计算机管理-服务和应用程序-消息队列-专用队列”中新建列队名称Demo: static void SendAndReceiveMsg() { MessageQueue m ...

  2. 转载(Asp.net Core 中试使用ZKWeb.System.Drawing)

    完美 原文Link: https://www.yanning.wang/archives/644.html 记录下做备份. 很少用Linux服务器. 这下可给整的够呛, 特别是按照官网竟然还不行, 所 ...

  3. 工作总结 1 sql写法 insert into select from 2 vs中 obj文件和bin文件 3 npoi 模板copy CopySheet 最好先全部Copy完后 再根据生成sheet写数据 4 sheet.CopyRow(rowsindex, rowsindex + x); 5 npoi 复制模板如果出现单元格显示问题

    我们可以从一个表中复制所有的列插入到另一个已存在的表中: INSERT INTO table2SELECT * FROM table1; 或者我们可以只复制希望的列插入到另一个已存在的表中: INSE ...

  4. CSS 选择器 :last-child与:last-of-type的区别

    :last-child----represents the last element among a group of sibling elements. CSS伪类 :last-child 代表在一 ...

  5. springboot学习(一) spring-boot是什么

    1.简介 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程. 2.主要优点 ①  使配置变得简单 ②  使编码变得简单 ③  使 ...

  6. MySQL 查询 数据库有多少表 表名是哪些

    1.查询sjcenter数据库里开头为sj_demo和sj_onlyinv的所有表的总条数 select sum(table_rows) from (select table_name,table_r ...

  7. oracle中导出表的结构和数据

    在linux环境上: exp user_name/password@//ip_address:1521/service_name file=aa.sql tables=\(table_name\); ...

  8. xcode下载低版本模拟器速度缓慢解决方案

    随着苹果系统的更新和迭代,现在app开发中需要适配的除了需要适配屏幕尺寸以外,还需要适配系统版本.系统版本测试如果有条件可以使用各种系统版本的真机进行适配,如果没有这个条件,也可以采用xcode的模拟 ...

  9. Redis源码阅读-sds字符串源码阅读

    redis使用sds代替char *字符串, 其定义如下: typedef char *sds; struct sdshdr { unsigned int len; unsigned int free ...

  10. 【Python + Selenium】之JS定位总结

    感谢:小琰子 Python+Selenium 脚本中的一些js的用法汇总: 1.滚动条 driver.set_window_size(500,500) js = "window.scroll ...