当前位置:网站首页>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;
}
};
边栏推荐
- K8s deployment of highly available PostgreSQL Cluster -- the road to building a dream
- Introduction to data platform
- The pie chart with dimension lines can set various parameter options
- Easydss anonymous live channel data volume instability optimization scheme sharing
- 单目双视三维坐标确定
- ZUCC_ Principles of compiling language and compilation_ Experiment 0607 grammar analysis ll analysis
- Use cpulimit to free up your CPU
- Using skills of xargs -- the way to build a dream
- 【力扣10天SQL入门】Day3
- Two methods of QT exporting PDF files
猜你喜欢

rpiplay实现树莓派AirPlay投屏器

K8s deployment of highly available PostgreSQL Cluster -- the road to building a dream

Qt 中发送自定义事件

How to improve the customer retention rate in the operation of independent stations? Customer segmentation is very important!

ZUCC_ Principles of compiling language and compilation_ Experiment 0607 grammar analysis ll analysis

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

原生小程序用画布制作海报,等比例缩放,和uniapp差不多就是写法有点不同

liunx服务器 telnet 带用户名 端口登陆方法

關於ETL看這篇文章就够了,三分鐘讓你明白什麼是ETL

Mysql数据(Liunx环境)定时备份
随机推荐
Introduction to data platform
数据中台:数据治理概述
New technology practice, encapsulating the permission application library step by step with the activity results API
Centos7 installation of jdk8, mysql5.7 and Navicat connection to virtual machine MySQL and solutions (solutions to MySQL download errors are attached)
Easycvr invokes the interface parameter acquisition method and precautions of device video recording on the page
定时备份数据库脚本
QT writing security video monitoring system 36 onvif continuous movement
Mysql数据(Liunx环境)定时备份
RuntimeError: Missing dependencies:XXX
Distributed | how to make "secret calls" with dble
Detailed explanation of Base64 coding and its variants (to solve the problem that the plus sign changes into a space in the URL)
One development skill a day: how to establish P2P communication based on webrtc?
【团队管理】测试团队绩效管理的25点小建议
Vscode install the remote -wsl plug-in to connect to the local WSL
[explain the difference between operation and maintenance and network engineering]
[10 day SQL introduction] Day2
input的聚焦后的边框问题
关于ETL看这篇文章就够了,三分钟让你明白什么是ETL
Qt 中发送自定义事件
PHP代码加密的几种方案