当前位置:网站首页>1704. judge whether the two halves of a string are similar
1704. judge whether the two halves of a string are similar
2022-06-24 08:52:00 【Drag is me】
leetcode Force button to brush questions and punch in
subject :1704. Determine whether the two halves of a string are similar
describe : Give you an even length string s . Split it into two halves with the same growth , The first half is a , The latter half is b .
Two strings be similar The premise is that they all contain the same number of vowels (‘a’,‘e’,‘i’,‘o’,‘u’,‘A’,‘E’,‘I’,‘O’,‘U’). Be careful ,s It may contain both upper and lower case letters .
If a and b be similar , return true ; otherwise , return false .
Their thinking
1、 The first a and b Take it out ;
2、 Calculation a and b Number of each vowel letter ;
Source code ##
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;
}
};
边栏推荐
- JS to find and update the specified value in the object through the key
- 教程篇(5.0) 08. Fortinet安全架构集成与FortiXDR * FortiEDR * Fortinet 网络安全专家 NSE 5
- 数组相向指针系列
- opencv最大值滤波(不局限于图像)
- 【牛客】把字符串转换成整数
- 等保备案是什么意思?应该去哪里办理备案?
- Liunx change the port number of vsftpd
- Numpy 中的方法汇总
- The pie chart with dimension lines can set various parameter options
- "Unusual proxy initial value setting is not supported", causes and Solutions
猜你喜欢

【NOI模拟赛】寄(树形DP)

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

Jenkins自动化部署,连接不到所依赖的服务【已解决】

【牛客】把字符串转换成整数

關於ETL看這篇文章就够了,三分鐘讓你明白什麼是ETL
![打印出来的对象是[object object],解决方法](/img/fc/9199e26b827a1c6304fcd250f2301e.png)
打印出来的对象是[object object],解决方法

【LeetCode】415. 字符串相加

Telnet port login method with user name for liunx server

Xiaohei ai4code code baseline nibble 1

【团队管理】测试团队绩效管理的25点小建议
随机推荐
Prompt code when MySQL inserts Chinese data due to character set problems: 1366
MySQL | 视图《康师傅MySQL从入门到高级》笔记
数据中台:民生银行的数据中台实践方案
110. balanced binary tree recursive method
Become an IEEE student member
【量化投资】离散傅里叶变换求数组周期
基于QingCloud的地理信息企业研发云解决方案
KaFormer个人笔记整理
What is the future development trend of Business Intelligence BI
MySQL | store notes of Master Kong MySQL from introduction to advanced
Wan Weiwei, a researcher from Osaka University, Japan, introduced the rapid integration method and application of robot based on WRS system
不能改变虚拟机电源状态报错解决方案
pymysql 向MySQL 插入数据无故报错
À propos de ETL il suffit de lire cet article, trois minutes pour vous faire comprendre ce qu'est ETL
Floating error waiting for changelog lock
【LeetCode】387. 字符串中的第一个唯一字符
Xiaohei ai4code code baseline nibble 1
打印出来的对象是[object object],解决方法
Analyze the meaning of Internet advertising terms CPM, CPC, CPA, CPS, CPL and CPR
[pytoch basic tutorial 31] youtubednn model analysis