当前位置:网站首页>【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
Reflex WMS Intermediate Series 7: What should I do if I want to cancel the picking of an HD that has finished picking but has not yet been loaded?
Install mysql using docker
esp32经典蓝牙和单片机连接,,,手机蓝牙作为主机
Nanoprobes多组氨酸 (His-) 标签标记:重组蛋白检测方案
Oracle19c安装图文教程
【web】理解 Cookie 和 Session 机制
局部敏感哈希:如何在常数时间内搜索Embedding最近邻
罗德里格斯公式(Rodrigues‘ Rotation Formula)推导
Safety (2)
随机推荐
字典常用方法
工程师如何对待开源
Good News | AR opens a new model for the textile industry, and ALVA Systems wins another award!
Nanoprobes免疫测定丨FluoroNanogold试剂免疫染色方案
How engineers treat open source
【ORB_SLAM2】void Frame::AssignFeaturesToGrid()
架构:分布式任务调度系统(SIA-Task)简介
【Unity入门计划】2D Game Kit:初步了解2D游戏组成
Swift运行时(派发机制)
BioVendor Human Club Cellular Protein (CC16) Elisa Kit Research Fields
BI-SQL丨WHILE
Nanoprobes丨1-巯基-(三甘醇)甲醚功能化金纳米颗粒
Lombok
CASE2023
忽晴忽雨
永磁同步电机36问(二)——机械量与电物理量如何转化?
The first time I wrote a programming interview question for Niu Ke: input a string and return the letter with the most occurrences of the string
Rasa 3 x learning series - Rasa - 4873 dispatcher Issues. Utter_message study notes
* 比较版本号
canal同步Mariadb到Mysql