当前位置:网站首页>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();
}
}
边栏推荐
- EOS的共识机制与区块生成
- 朴素贝叶斯
- nyoj1185最大最小值(线段树)
- swig 语法介绍
- Letter from Silicon Valley: Act fast, Facebook, Quora and other successful "artifacts"!
- 【分享】代码编程习惯:在多参数的方法的情况下需要对方法整理-即最多参数的方法为主要实现
- 分布式事务解决方案
- 【着色器实现Flicker“DJ”闪烁效果_Shader效果第十五篇】
- Version Control | Longzhi invites you to go to the GOPS Global Operation and Maintenance Conference to explore the road of large-scale, agile, high-quality and open software development and operation
- LeetCode刷题(8)
猜你喜欢

莅临GOPS大会龙智展位,获取Forrester最新报告:《Forrester Wave:2021年第四季度企业服务管理报告》

机器学习——集成学习

解决2022Visual Studio中scanf返回值被忽略问题

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

Official release 2022 Nanjing Zhibo Expo is scheduled to be held in Xinzhuang National Exhibition in October

普通二本毕业八年,京东就职两年、百度三年,分享大厂心得

后缀自动机(SAM)——黑盒使用方案

2022 CCF国际AIOps挑战赛决赛暨AIOps研讨会报名已开启

No developers, received a job to develop an IoT system, do you want to do it?

Version Control | Longzhi invites you to go to the GOPS Global Operation and Maintenance Conference to explore the road of large-scale, agile, high-quality and open software development and operation
随机推荐
[7.29-8.5] Review of wonderful technical blog posts in the writing community
Go 语言快速入门指南: 基本类型
Linux: Remember to install MySQL8 on CentOS7 (blog collection)
STM32H743IIT6学习笔记02——USART
Web3 中的安全问题和防范
Student Information Management System (first time...)
消息中间件汇总
2022杭电多校联赛第六场 题解
Go compilation principle series 9 (function inlining)
Apache APISIX Ingress v1.5-rc1 released
Go Quick Start Guide: Basic Types
Byte Qiu Zhao confused me on both sides, and asked me under what circumstances would the SYN message be discarded?
shell编程流程控制练习
解决 cuDNN launch failure 错误
Machine Learning - Ensemble Learning
Mathcad 15.0软件安装包下载及安装教程
795. 前缀和
学习用于视觉跟踪的深度紧凑图像表示
SonarQube即将亮相第十八届GOPS全球运维大会
hdu1455 Sticks (search+pruning+pruning+.....+pruning)