当前位置:网站首页>2022.08.01_每日一题
2022.08.01_每日一题
2022-08-05 11:48:00 【诺.い】
1374. 生成每种字符都是奇数个的字符串
题目描述
给你一个整数 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
coding
class Solution {
public String generateTheString(int n) {
return new StringBuffer(n)
.append("a".repeat(n - 1))
.append(n % 2 == 0 ? 'b' : 'a')
.toString();
}
}
边栏推荐
- nyoj1185最大最小值(线段树)
- Four, kubeadm single master
- hdu4545 Magic String
- What do T and Z in the time format 2020-01-13T16:00:00.000Z represent and how to deal with them
- PHP高级检索功能的实现以及动态拼接SQL
- 并非富人专属,一文让你对NFT改观
- Linux: Remember to install MySQL8 on CentOS7 (blog collection)
- el-menu箭头改为右下
- 澳洲站:电吹风AS/NZS 60335.2.23: 2017 安全标准测试
- 平安萌娃卡保险怎么样?让父母读懂几个识别产品的方法
猜你喜欢

官方发布·2022南京智博会定于10月份在新庄国展召开

查询优化(TTFB过长)left join索引未生效

Flink Yarn Per Job - 启动TM,向RM注册,RM分配solt

365天挑战LeetCode1000题——Day 050 在二叉树中增加一行 二叉树

后缀自动机(SAM)——黑盒使用方案
The importance of parameter naming, remember a JDBC parameter conflict

Go编译原理系列9(函数内联)

并非富人专属,一文让你对NFT改观

硅谷来信:快速行动,Facebook、Quora等成功的“神器”!

Security Issues and Prevention in Web3
随机推荐
澳洲站:电吹风AS/NZS 60335.2.23: 2017 安全标准测试
软件设计七大原则之开闭原则(Open-Closed Principle, OCP)
Wingide 快捷键
Cesium.js 三维土壤地质剖面分割挖掘
A woman is the most beautiful life in the world
2-2.基金的投资交易与结算
机器学习——逻辑回归
知乎提问:中国是否还能实现伟大民族复兴
祝所有码农七夕快乐~
普通二本毕业八年,京东就职两年、百度三年,分享大厂心得
Support Vector Machine SVM
.NET in-depth analysis of the LINQ framework (6: LINQ execution expressions)
Three.js 点击模型,高亮发光模型外轮廓
The training set Loss converges, but the test set Loss oscillates violently?
What do T and Z in the time format 2020-01-13T16:00:00.000Z represent and how to deal with them
Official release 2022 Nanjing Zhibo Expo is scheduled to be held in Xinzhuang National Exhibition in October
手把手教你定位线上MySQL慢查询问题,包教包会
Security Issues and Prevention in Web3
The importance of parameter naming, remember a JDBC parameter conflict
官方发布·2022南京智博会定于10月份在新庄国展召开