当前位置:网站首页>1704. 判断字符串的两半是否相似
1704. 判断字符串的两半是否相似
2022-06-24 07:06:00 【拽拽就是我】
leetcode力扣刷题打卡
题目:1704. 判断字符串的两半是否相似
描述:给你一个偶数长度的字符串 s 。将其拆分成长度相同的两半,前一半为 a ,后一半为 b 。
两个字符串 相似 的前提是它们都含有相同数目的元音(‘a’,‘e’,‘i’,‘o’,‘u’,‘A’,‘E’,‘I’,‘O’,‘U’)。注意,s 可能同时含有大写和小写字母。
如果 a 和 b 相似,返回 true ;否则,返回 false 。
解题思路
1、先把a 和b拎出来;
2、计算a和b各自元音字母的个数;
原代码##
class Solution {
public:
bool isyy(char ch) {
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
return true;
} else {
return false;
}
}
bool halvesAreAlike(string s) {
int len = s.size();
string a = s.substr(0, len / 2);
string b = s.substr(len / 2);
int cnta = 0, cntb = 0;
for (int i = 0; i < len / 2; ++i) {
if (isyy(a[i])) cnta++;
}
for (int i = 0; i < len / 2; ++i) {
if (isyy(b[i])) cntb++;
}
return cnta == cntb;
}
};
边栏推荐
- 饼状统计图,带有标注线,都可以自行设定其多种参数选项
- Battle history between redis and me under billion level traffic
- [force deduction 10 days SQL introduction] Day3
- Base64编码详解及其变种(解决加号在URL变空格问题)
- 分布式 | 如何与 DBLE 进行“秘密通话”
- Xiaohei ai4code code baseline nibble 1
- 提高INSERT速度
- Background management of uniapp hot update
- Using ngrok for intranet penetration
- Easycvr invokes the interface parameter acquisition method and precautions of device video recording on the page
猜你喜欢

Liunx Mysql安装

À propos de ETL il suffit de lire cet article, trois minutes pour vous faire comprendre ce qu'est ETL

rpiplay实现树莓派AirPlay投屏器

疫情、失业,2022,我们高喊着摆烂和躺平!

日本大阪大学万伟伟研究员介绍基于WRS系统机器人的快速集成方法和应用

数据库迁移从PostgreSQL迁移到 MYSQL

Qt 中发送自定义事件

MySQL 因字符集问题插入中文数据时提示代码 :1366

js中通过key查找和更新对象中指定值的方法

原生小程序用画布制作海报,等比例缩放,和uniapp差不多就是写法有点不同
随机推荐
leetcode 1642. Furthest building you can reach
为什么ping不通,而traceroute却可以通
liunx服务器 telnet 带用户名 端口登陆方法
The pie chart with dimension lines can set various parameter options
Centos7 installation of jdk8, mysql5.7 and Navicat connection to virtual machine MySQL and solutions (solutions to MySQL download errors are attached)
所说的Get post:请求的区别,你真的知道了吗??????
How to replace the web player easyplayerproactivex Key in OCX?
api平台通用签名机制
String to Base64
QT writing security video monitoring system 36 onvif continuous movement
ZUCC_编译语言原理与编译_实验06 07 语法分析 LL 分析
中国芯片独角兽公司
Rescue system -- the application of read-write separation
利用ngrok做内网穿透
Redis的Cluster集群数据倾斜
Detailed explanation of Base64 coding and its variants (to solve the problem that the plus sign changes into a space in the URL)
Earthly container image construction tool -- the road to dream
原生小程序用画布制作海报,等比例缩放,和uniapp差不多就是写法有点不同
orb slam build bug: undefined reference to symbol ‘_ ZN5boost6system15system_ categoryEv‘
uniapp 热更新后台管理