当前位置:网站首页>Leetcode 984. String without AAA or BBB (thought of netizens)
Leetcode 984. String without AAA or BBB (thought of netizens)
2022-06-29 18:23:00 【I'm not xiaohaiwa~~~~】

Given two integers a and b , return arbitrarily character string s , Demand satisfaction :
- s The length of is a + b, And contains exactly a individual ‘a’ Letters and b individual ‘b’ Letter ;
- Substring ‘aaa’ Not in s in ;
- Substring ‘bbb’ Not in s in .
Example 1:
Input :a = 1, b = 2
Output :"abb"
explain :"abb", "bab" and "bba" It's all the right answers .
Example 2:
Input :a = 4, b = 1
Output :"aabaa"
Tips :
- 0 <= a, b <= 100
- For a given a and b, Ensure that there are s
Code:
class Solution {
public:
string strWithout3a3b(int A, int B) {
// Guarantee A > B
string str = "";
char a = 'a', b = 'b';
if (A < B) {
swap(A, B);
swap(a, b);
}
while (A > 0 || B > 0) {
if (A > 0) {
str.push_back(a);
A --;
}
if (A > B) {
str.push_back(a);
A --;
}
if (B > 0) {
str.push_back(b);
B --;
}
}
return str;
}
};
边栏推荐
- [target tracking] |stark configuration win OTB
- 3H proficient in opencv (VIII) - shape detection
- Xiaomai technology x hologres: high availability of real-time data warehouse construction of ten billion level advertising
- js两个二维数组合并并去除相同项(整理)
- How QQ opens online customer service
- 国内酒店交易DDD应用与实践——理论篇
- Detailed analysis on the use of MySQL stored procedure loop
- Request header field XXXX is not allowed by access control allow headers in preflight response
- Kubekey2.2.1 kubernetes1.23.7 offline package production +harbor Department summer and upload image
- WBF:检测任务NMS后虑框新方式?
猜你喜欢

Kubekey2.2.1 kubernetes1.23.7 offline package production +harbor Department summer and upload image

Niuke small Bai monthly race 52 D ring insectivorous (feet +st table)

The soft youth under the blessing of devcloud makes education "smart" in the cloud

Proxmox VE Install 7.2

js两个二维数组合并并去除相同项(整理)

Niuke Xiaobai monthly race 52 E group logarithmic sum (inclusion exclusion theorem + dichotomy)

牛客小Bai月赛52 D 环上食虫(尺取+st表)

源码安装MAVROS

jdbc_相关代码

Adobe Premiere基础-不透明度(蒙版)(十一)
随机推荐
Codeworks 5 questions per day (1700 for each) - the next day
VMware installation esxi
Longest XOR path (dfs+01trie)
3H proficient in opencv (VIII) - shape detection
3H proficient in opencv (VII) - color detection
Configure the local domain name through the hosts file
工作流模块Jar包启动报错:liquibase – Waiting for changelog lock….
Lodash deep copy usage
MaxCompute Studio
Adobe Premiere基礎-聲音調整(音量矯正,降噪,電話音,音高換擋器,參數均衡器)(十八)
[tcapulusdb knowledge base] tcapulusdb doc acceptance - Introduction to creating game area
Maximum length of palindrome substring (string hash + binary)
markdown知识轻轻来袭
数据分析基础--预测模型
jdbc_相關代碼
小迈科技 X Hologres:高可用的百亿级广告实时数仓建设
[tcapulusdb knowledge base] tcapulusdb system user group introduction
Yolov6+tensorrt+onnx: deployment based on win10+tensorrt8+yolov6+onnx
记录服务器被入侵病毒:ssh密码被更改登录失败、恶意程序跑满了cpu、jar包启动失败自动kill、一直弹出You have new mail in /var/spool/mail/root
Adobe Premiere Basics - general operations for editing material files (offline files, replacing materials, material labels and grouping, material enabling, convenient adjustment of opacity, project pa