当前位置:网站首页>"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
n
is an even number, you can getn-1
a
and1
b
;- When
n
is an odd number,n
can 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:
边栏推荐
猜你喜欢
随机推荐
力扣每日一题-第46天-344. 反转字符串
【LeetCode】622. 设计循环队列
idea 配置resin
J9数字论:互联网跨链桥有什么作用呢?
Wintun:一款惊艳的 WireGuard 虚拟网卡接口驱动
服务器Centos7 静默安装Oracle Database 12.2
In action: 10 ways to implement delayed tasks, with code!
EasyExcel实现动态列解析和存表
Silver circ: letter with material life insurance products should be by the insurance company is responsible for the management
Five data structures of Redis and their corresponding usage scenarios
磁盘分区的知识
Leetcode刷题——23. 合并K个升序链表
【 LeetCode 】 1374. Generate each character string is an odd number
es 官方诊断工具
The so-called fighting skill again gao also afraid of the chopper - partition, depots, table, and the merits of the distributed
对话亚洲高校首个博士论文奖-裘捷中丨KDD2022
Leetcode刷题——字符串相加相关题目(415. 字符串相加、面试题 02.05. 链表求和、2. 两数相加)
Meta 与苹果的元宇宙碰撞
Cannot find declaration to go to
【手撕AHB-APB Bridge】~ AMBA总线 之 APB