当前位置:网站首页>"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:

边栏推荐
猜你喜欢

2022-07-28

LM小型可编程控制器软件(基于CoDeSys)笔记二十五:plc的数据存储区(数字量输入通道部分)

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

MySQL安装配置教程(超级详细)

顺序查找和折半查找,看这篇就够了

Redis cluster configuration

腾讯云孟凡杰:我所经历的云原生降本增效最佳实践案例

Thread线程类基本使用(下)

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

Parse common methods in the Collection interface that are overridden by subclasses
随机推荐
SQL 入门之第一讲——MySQL 8.0.29安装教程(windows 64位)
「 每日一练,快乐水题 」1374. 生成每种字符都是奇数个的字符串
JWT学习
LeetCode - 105. 从前序与中序遍历序列构造二叉树;023.合并K个升序链表
姑姑:给小学生出点口算题
AI科学家:自动发现物理系统的隐藏状态变量
golang刷leetcode动态规划(12)最小路径和
SQL Server实现group_concat功能
In action: 10 ways to implement delayed tasks, with code!
分享一个 web 应用版本监测 (更新) 的工具库
六石管理学:入门机会只有一次,先把产品做好
Thread线程类基本使用(上)
解析Collection接口中的常用的被实现子类重写的方法
Redis 5 种数据结构及对应使用场景
如何解决图像分类中的类别不均衡问题?不妨试试分开学习表征和分类器
MaxCompute 近期发布上线的版本的 SQL 引擎新功能参数化视图有什么优势?
网络协议介绍
ECCV 2022 | 通往数据高效的Transformer目标检测器
解析List接口中的常用的被实现子类重写的方法
Caldera(一)配置完成的虚拟机镜像及admin身份简单使用