当前位置:网站首页>"A daily practice, happy water problem" 1374. Generate a string with an odd number of each character
"A daily practice, happy water problem" 1374. Generate a string with an odd number of each character
2022-08-02 23:03:00 【who eats mints】
Article table of contents
Like the original title:
1374. Generate an odd number of each characterString
*Topic description:
Given an integer n, please return a string of n characters, where each character occurs exactly an odd number of times in the string.
The returned string must contain only lowercase English letters.If there are multiple strings that meet the requirements of the question, just return any one of them.
*Solution ideas:
- Simulate according to the meaning of the question; When
nis an even number, you can getn-1aand1b;- When
nis an odd number,ncan bea; - over;
*C++ code:
class Solution {public:string generateTheString(int n) {string str;if(n % 2 == 0){///for(int i = 0; i <n -1; i++){str += 'a';}str += 'b';}else{///< odd numberfor(int i = 0; i <n; i++){str += 'a';}}return str;}}; Result display:

边栏推荐
猜你喜欢

成为黑客不得不学的语言,看完觉得你们还可吗?

解析Collection接口中的常用的被实现子类重写的方法

SQL 嵌套 N 层太长太难写怎么办?

太魔人招新啦|快来加入我们吧!

对话亚洲高校首个博士论文奖-裘捷中丨KDD2022

J9 Digital Currency Theory: Identifying Web3's New Scarcity: Open Source Developers

服务器Centos7 静默安装Oracle Database 12.2

「面试必会」这应该是最有深度的TCP三次握手、四次挥手细节讲解

J9数字货币论:识别Web3新的稀缺性:开源开发者

B站HR对面试者声称其核心用户都是生活中的Loser
随机推荐
银保监会:人身险产品信披材料应由保险公司总公司统一负责管理
Async的线程池使用的哪个?
「面试必会」这应该是最有深度的TCP三次握手、四次挥手细节讲解
基于 outline 实现头像剪裁以及预览
Translate My Wonderful | July Moli Translation Program Winners Announced
J9数字论:互联网跨链桥有什么作用呢?
遇上Mysql亿级优化,怎么办
实战:10 种实现延迟任务的方法,附代码!
SCANIA SCANIA OTL tag is introduced
Soft Exam ----- UML Design and Analysis (Part 2)
J9数字货币论:识别Web3新的稀缺性:开源开发者
TPAMI2022 | TransCL:基于Transformer的压缩学习,更灵活更强大
7月29-31 | APACHECON ASIA 2022
腾讯云孟凡杰:我所经历的云原生降本增效最佳实践案例
idea 配置resin
基于“无依赖绝对定位”实现的圣杯三栏布局
A Review of Nature Microbiology: Focusing on the Algae--Ecological Interface of Phytoplankton-Bacteria Interactions
成为黑客不得不学的语言,看完觉得你们还可吗?
J9 digital theory: the Internet across chain bridge has what effect?
所谓武功再高也怕菜刀-分区、分库、分表和分布式的优劣