当前位置:网站首页>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;
}
};
边栏推荐
- Double pointer analog
- Earthly container image construction tool -- the road to dream
- QT source code analysis -- QObject (2)
- Fast and slow pointer series
- Mysql数据(Liunx环境)定时备份
- 数据中台:中台架构及概述
- JS to find and update the specified value in the object through the key
- 数云发布2022美妆行业全域消费者数字化经营白皮书:全域增长破解营销难题
- Xiaohei ai4code code baseline nibble 1
- IDEA另起一行快捷键
猜你喜欢
![[team management] 25 tips for testing team performance management](/img/bd/0ef55630de43efcf5aa663f3099fce.jpg)
[team management] 25 tips for testing team performance management

数据库迁移从PostgreSQL迁移到 MYSQL

“论解不了数独所以选择做个数独游戏这件事”

Background management of uniapp hot update

【E325: ATTENTION】vim编辑时报错

KaFormer个人笔记整理

"Unusual proxy initial value setting is not supported", causes and Solutions

MBA-day25 最值问题-应用题

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

MySQL | 视图《康师傅MySQL从入门到高级》笔记
随机推荐
520. 检测大写字母
What is graph neural network? Figure what is the use of neural networks?
Get screen width and height tool class
解决:模型训练时loss出现nan
MyCAT读写分离与MySQL主从同步
Numpy 中的方法汇总
工具类
GradScaler MaxClipGradScaler
2022 spring recruitment interview summary
项目部署相关
何时使用RDD和DataFrame/DataSet
Solving linear equations with MATLAB ax=b
偶然间得到的framework工具类 自用
110. balanced binary tree recursive method
双指针模拟
every()、map()、forEarch()方法。数组里面有对象的情况
liunx服务器 telnet 带用户名 端口登陆方法
Summary of methods in numpy
MySQL | 存储《康师傅MySQL从入门到高级》笔记
Jenkins is deployed automatically and cannot connect to the dependent service [solved]