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

边栏推荐
猜你喜欢

KDD 2022 | 深度图神经网络中的特征过相关:一个新视角

LeetCode - 105. 从前序与中序遍历序列构造二叉树;023.合并K个升序链表

What is a Field Service Management System (FSM)?what is the benefit?

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

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

AI Scientist: Automatically discover hidden state variables of physical systems

基于 outline 实现头像剪裁以及预览
分享一个 web 应用版本监测 (更新) 的工具库

扫码预约 | 观看Apache Linkis数据处理实践以及计算治理能力

TPAMI2022 | TransCL:基于Transformer的压缩学习,更灵活更强大
随机推荐
es DELETE index 源码分析
Five data structures of Redis and their corresponding usage scenarios
实现fashion_minst服装图像分类
技术分享 | Apache Linkis 快速集成网页IDE工具 Scriptis
J9数字货币论:识别Web3新的稀缺性:开源开发者
golang源码分析之geoip2-golang
解析Collection接口中的常用的被实现子类重写的方法
所谓武功再高也怕菜刀-分区、分库、分表和分布式的优劣
es 读流程源码解析
setup语法糖 defineProps defineEmits defineExpose
MaxCompute 近期发布上线的版本的 SQL 引擎新功能参数化视图有什么优势?
六石管理学:入门机会只有一次,先把产品做好
Electron User Guide Beginning Experience
golang源码分析:time/rate
新增指令 v-memo
分享一个 web 应用版本监测 (更新) 的工具库
模板的进阶
Cannot find declaration to go to
ALV报表学习总结
Introduction of uncommon interfaces of openlayers