当前位置:网站首页>【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';
}
};
边栏推荐
猜你喜欢

Talking about the "horizontal, vertical and vertical" development trend of domestic ERP

canal同步Mariadb到Mysql

feign调用不通问题,JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r

因为WiFi原因navicat 无法连接数据库Mysql

第11章_数据库的设计规范

使用DBeaver进行mysql数据备份与恢复

项目场景 with ERRTYPE = cudaError CUDA failure 999 unknown error

Pinduoduo leverages the consumer expo to promote the upgrading of domestic agricultural products brands and keep pace with international high-quality agricultural products

使用docker安装mysql

BI - SQL 丨 WHILE
随机推荐
Oracle数据类型介绍
面对职场“毕业”,PM&PMO应该如何从容的应对?如何跳槽能够大幅度升职加薪?
CASE2023
Remember a gorm transaction and debug to solve mysql deadlock
Nanoprobes纳米探针丨Nanogold偶联物的特点和应用
【Unity入门计划】2D Game Kit:初步了解2D游戏组成
四元数、罗德里格斯公式、欧拉角、旋转矩阵推导和资料
第11章_数据库的设计规范
1688API
51. 数字排列
因为WiFi原因navicat 无法连接数据库Mysql
Swift运行时(派发机制)
微信小程序异步回调函数恶梦和解决办法
Outsourcing worked for three years, it was abolished...
Unable to log in to the Westward Journey
机器人领域期刊会议汇总
JVM调优实战
JS中获取对象数据类型的键值对的键与值
罗德里格斯公式(Rodrigues‘ Rotation Formula)推导
微服务:微智能在软件系统的简述