当前位置:网站首页>"A daily practice, happy water problem" 1374. Generate a string with an odd number of each character
"A daily practice, happy water problem" 1374. Generate a string with an odd number of each character
2022-08-02 23:03:00 【who eats mints】
Article table of contents
Like the original title:
1374. Generate an odd number of each characterString
*Topic description:
Given an integer n, please return a string of n characters, where each character occurs exactly an odd number of times in the string.
The returned string must contain only lowercase English letters.If there are multiple strings that meet the requirements of the question, just return any one of them.
*Solution ideas:
- Simulate according to the meaning of the question; When
n
is an even number, you can getn-1
a
and1
b
;- When
n
is an odd number,n
can bea
; - over;
*C++ code:
class Solution {public:string generateTheString(int n) {string str;if(n % 2 == 0){///for(int i = 0; i <n -1; i++){str += 'a';}str += 'b';}else{///< odd numberfor(int i = 0; i <n; i++){str += 'a';}}return str;}};
Result display:
边栏推荐
猜你喜欢
LeetCode:622. 设计循环队列【模拟循环队列】
解析Collection接口中的常用的被实现子类重写的方法
Translate My Wonderful | July Moli Translation Program Winners Announced
PG 之 SQL执行计划
分享一个 web 应用版本监测 (更新) 的工具库
特拉维夫大学 | Efficient Long-Text Understanding with Short-Text Models(使用短文本模型进行高效的长文本理解)
分布式事务
2022-07-28
即时通讯开发移动端网络短连接的优化手段
对话亚洲高校首个博士论文奖-裘捷中丨KDD2022
随机推荐
使用位运算实现加减乘除(+、-、*、/)及比较器的用法
4 kmiles join YiSheng group, with more strong ability of digital business, accelerate China's cross-border electricity full domain full growth
姑姑:给小学生出点口算题
Redis 5 种数据结构及对应使用场景
J9 digital theory: the Internet across chain bridge has what effect?
Flutter with internationalized adapter automatically generated
如何解决图像分类中的类别不均衡问题?不妨试试分开学习表征和分类器
基于“无依赖绝对定位”实现的圣杯三栏布局
磁盘分区的知识
SQL 入门之第一讲——MySQL 8.0.29安装教程(windows 64位)
golang刷leetcode 经典(10) tire树与ac自动机
美国爱荷华州立大学| Improving Distantly Supervised Relation Extraction by Natural Language Inference(通过自然语言推理改进远程监督关系提取)
力扣每日一题-第46天-344. 反转字符串
JWT学习
2022-07-26
Soft Exam ----- UML Design and Analysis (Part 2)
训练双塔检索模型,可以不用query-doc样本了?明星机构联合发文
B站HR对面试者声称其核心用户都是生活中的Loser
J9数字货币论:识别Web3新的稀缺性:开源开发者
二丙二醇甲醚醋酸酯