当前位置:网站首页>「 每日一练,快乐水题 」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;
}
};
结果展示:

边栏推荐
- Translate My Wonderful | July Moli Translation Program Winners Announced
- golang刷leetcode 经典(11) 朋友圈
- Shell: conditional statements
- es 读流程源码解析
- 7月29-31 | APACHECON ASIA 2022
- ShardingSphere-proxy +PostgreSQL实现读写分离(静态策略)
- 实战:10 种实现延迟任务的方法,附代码!
- 即时通讯开发移动端网络短连接的优化手段
- J9 Digital Currency Theory: Identifying Web3's New Scarcity: Open Source Developers
- J9数字货币论:识别Web3新的稀缺性:开源开发者
猜你喜欢

JWT学习

PG's SQL execution plan

ECCV 2022 | 通往数据高效的Transformer目标检测器

溜不溜是个问题

Introduction of uncommon interfaces of openlayers

Fiddle设置接口数据用指定工具查看;Sublime Text设置json数据格式化转换

Five data structures of Redis and their corresponding usage scenarios

Caldera(一)配置完成的虚拟机镜像及admin身份简单使用

unittest自动化测试框架总结

ShapeableImageView 的使用,告别shape、三方库
随机推荐
GNN教程:图神经网络基础知识!
TPAMI2022 | TransCL:基于Transformer的压缩学习,更灵活更强大
MaxCompute 的SQL 引擎参数化视图具体有哪些增强功能?
Office2021 安装MathType
Introduction of uncommon interfaces of openlayers
Thread线程类基本使用(下)
所谓武功再高也怕菜刀-分区、分库、分表和分布式的优劣
Based on OpenGL glaciers and firebird (illumination calculation model, visual, particle system)
JWT学习
golang刷leetcode 经典(11) 朋友圈
Parse common methods in the Collection interface that are overridden by subclasses
一些不错的博主
Flutter自带国际化适配自动生成方案
健康报告-设计与实现
js Fetch返回数据res.json()报错问题
golang刷leetcode 数学(1) 丑数系列
实现客户服务自助,打造产品知识库
Flutter with internationalized adapter automatically generated
什么是乙二醇二乙酸酯(EGDA)?
A Review of Nature Microbiology: Focusing on the Algae--Ecological Interface of Phytoplankton-Bacteria Interactions