当前位置:网站首页>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;
}
};
边栏推荐
- Introduction to data platform
- MySQL | 视图《康师傅MySQL从入门到高级》笔记
- 小程序云数据,数据请求一个集合数据的方法
- K8s deployment of highly available PostgreSQL Cluster -- the road to building a dream
- The pie chart with dimension lines can set various parameter options
- 双指针模拟
- 第七章 操作位和位串(三)
- leetcode 1268. Search suggestions system
- "Unusual proxy initial value setting is not supported", causes and Solutions
- Numpy 中的方法汇总
猜你喜欢

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

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

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

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

Wan Weiwei, a researcher from Osaka University, Japan, introduced the rapid integration method and application of robot based on WRS system

4275. Dijkstra序列

【NOI模拟赛】给国与时光鸡(构造)

Prompt code when MySQL inserts Chinese data due to character set problems: 1366

WebRTC系列-网络传输之5选择最优connection切换

MySQL | store notes of Master Kong MySQL from introduction to advanced
随机推荐
The pie chart with dimension lines can set various parameter options
【LeetCode】387. 字符串中的第一个唯一字符
剑指 Offer 55 - I. 二叉树的深度-dfs法
Become an IEEE student member
快慢指针系列
K8S部署高可用postgresql集群 —— 筑梦之路
Sword finger offer 55 - I. depth DFS method of binary tree
rpiplay实现树莓派AirPlay投屏器
从华为WeAutomate数字机器人论坛,看政企领域的“政务新智理”
Summary of methods in numpy
PHP code encryption + extended decryption practice
Database to query the quantity of books lent in this month. If it is higher than 10, it will display "more than 10 books lent in this month". Otherwise, it will display "less than 10 books lent in thi
QT source code analysis -- QObject (2)
Jenkins自动化部署,连接不到所依赖的服务【已解决】
Several schemes of PHP code encryption
China chip Unicorn Corporation
基于单片机开发的酒精浓度测试仪方案
216. 组合总和 III-枚举法
工具类
every()、map()、forEarch()方法。数组里面有对象的情况