当前位置:网站首页>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;
}
};
边栏推荐
- Using sonar for code checking
- K8S部署高可用postgresql集群 —— 筑梦之路
- 偶然间得到的framework工具类 自用
- SLAM14讲中Sophus包的安装问题
- 数据中台:民生银行的数据中台实践方案
- Detailed explanation of Base64 coding and its variants (to solve the problem that the plus sign changes into a space in the URL)
- MySQL | 视图《康师傅MySQL从入门到高级》笔记
- OpenCV每日函数 结构分析和形状描述符(7) 寻找多边形(轮廓)/旋转矩形交集
- 110. balanced binary tree recursive method
- WebRTC系列-网络传输之5选择最优connection切换
猜你喜欢
![[pytoch basic tutorial 31] youtubednn model analysis](/img/18/dbeab69894583f6e5230772ce44652.png)
[pytoch basic tutorial 31] youtubednn model analysis

input的聚焦后的边框问题

4274. 后缀表达式

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

教程篇(5.0) 08. Fortinet安全架构集成与FortiXDR * FortiEDR * Fortinet 网络安全专家 NSE 5

Pymysql inserts data into MySQL and reports an error for no reason

A tip to read on Medium for free

【Pytorch基础教程31】YoutubeDNN模型解析

It is enough to read this article about ETL. Three minutes will let you understand what ETL is

ZUCC_ Principles of compiling language and compilation_ Experiment 0607 grammar analysis ll analysis
随机推荐
Win11 blank when using VIM to view content in cmder
数组相向指针系列
2020中国全国各省市,三级联动数据,数据机构(数据来自国家统计局官网)
Camera projection matrix calculation
Fast and slow pointer series
Determination of monocular and binocular 3D coordinates
2022 spring recruitment interview summary
项目部署相关
【牛客】HJ1 字符串最后一个单词的长度
Earthly container image construction tool -- the road to dream
leetcode 1268. Search suggestions system
String to Base64
KaFormer个人笔记整理
MyCAT读写分离与MySQL主从同步
[10 day SQL introduction] Day2
Introduction to data platform
What is the future development trend of Business Intelligence BI
阿里资深软件测试工程师推荐测试人员必学——安全测试入门介绍
Xiaohei ai4code code baseline nibble 1
Database migration from PostgreSQL to MySQL