当前位置:网站首页>「 每日一练,快乐水题 」1374. 生成每种字符都是奇数个的字符串
「 每日一练,快乐水题 」1374. 生成每种字符都是奇数个的字符串
2022-08-02 19:47:00 【谁吃薄荷糖】
力扣原题:
*题目简述:
给你一个整数 n,请你返回一个含 n 个字符的字符串,其中每种字符在该字符串中都恰好出现 奇数次 。
返回的字符串必须只含小写英文字母。如果存在多个满足题目要求的字符串,则返回其中任意一个即可。
*解题思路:
- 根据题意进行模拟;
n为偶数时,则可以搞n-1个a与1个b的情况;n为奇数时,则可搞n个a即可;- over;
*C++代码:
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
{
///< 奇数
for(int i = 0; i < n; i++)
{
str += 'a';
}
}
return str;
}
};
结果展示:

边栏推荐
猜你喜欢
随机推荐
SQL Server安装教程
SCANIA SCANIA OTL tag is introduced
入职对接-hm项目
银保监会:人身险产品信披材料应由保险公司总公司统一负责管理
4 kmiles join YiSheng group, with more strong ability of digital business, accelerate China's cross-border electricity full domain full growth
[安洵杯 2019]easy_web
What is a Field Service Management System (FSM)?what is the benefit?
SQL Server数据类型转换函数cast()和convert()详解
【软件工程导论】软件工程导论笔记
网络协议介绍
当TIME_WAIT状态的TCP正常挥手,收到SYN后…
Flutter with internationalized adapter automatically generated
openlayers version update difference
js Fetch返回数据res.json()报错问题
Leetcode刷题——字符串相加相关题目(415. 字符串相加、面试题 02.05. 链表求和、2. 两数相加)
EMQX Newsletter 2022-07|EMQX 5.0 正式发布、EMQX Cloud 新增 2 个数据库集成
AI科学家:自动发现物理系统的隐藏状态变量
The so-called fighting skill again gao also afraid of the chopper - partition, depots, table, and the merits of the distributed
技术分享 | Apache Linkis 快速集成网页IDE工具 Scriptis
J9数字货币论:识别Web3新的稀缺性:开源开发者









