当前位置:网站首页>【LeetCode】1374. 生成每种字符都是奇数个的字符串
【LeetCode】1374. 生成每种字符都是奇数个的字符串
2022-08-02 02:40:00 【酥酥~】
题目
给你一个整数 n,请你返回一个含 n 个字符的字符串,其中每种字符在该字符串中都恰好出现 奇数次 。
返回的字符串必须只含小写英文字母。如果存在多个满足题目要求的字符串,则返回其中任意一个即可。
示例 1:
输入:n = 4
输出:“pppz”
解释:“pppz” 是一个满足题目要求的字符串,因为 ‘p’ 出现 3 次,且 ‘z’ 出现 1 次。当然,还有很多其他字符串也满足题目要求,比如:“ohhh” 和 “love”。
示例 2:
输入:n = 2
输出:“xy”
解释:“xy” 是一个满足题目要求的字符串,因为 ‘x’ 和 ‘y’ 各出现 1 次。当然,还有很多其他字符串也满足题目要求,比如:“ag” 和 “ur”。
示例 3:
输入:n = 7
输出:“holasss”
提示:
1 <= n <= 500
class Solution {
public:
string generateTheString(int n) {
if(n%2==1)
return string(n,'a');
return string(n-1,'a')+'b';
}
};
边栏推荐
- 项目场景 with ERRTYPE = cudaError CUDA failure 999 unknown error
- C#测试项目中属性的用法
- 1688以图搜货
- The principle and code implementation of intelligent follower robot in the actual combat of innovative projects
- ApiFox 基本使用教程(浅尝辄止,非广)
- OperatingSystemMXBean获取系统性能指标
- 内卷的正确打开方式
- Chopper webshell feature analysis
- mysql 查看死锁
- NAS和私有云盘的区别?1篇文章说清楚
猜你喜欢
随机推荐
【每日一道LeetCode】——1. 两数之和
IMU预积分的简单理解
How engineers treat open source
AI target segmentation capability for fast video cutout without green screen
Curriculum Vitae;CV
The state status is displayed incorrectly after the openGauss switch
Nacos源码分析专题(二)-服务注册
使用docker安装mysql
GTK RGB图像绘制
53. 最小的k个数
ALCCIKERS Shane 20191114
因为WiFi原因navicat 无法连接数据库Mysql
字典常用方法
[Server data recovery] Data recovery case of server Raid5 array mdisk disk offline
cocos中使用async await异步加载资源
2022牛客多校三_F G
罗德里格斯公式(Rodrigues‘ Rotation Formula)推导
Electronic Manufacturing Warehouse Barcode Management System Solution
项目场景 with ERRTYPE = cudaError CUDA failure 999 unknown error
通用客户端架构