public class Solution
{
private string M1(int A, int B)
{
StringBuilder sb = new StringBuilder();
int groupA = A / ;
int freeA = A % ;
int temp = groupA;
int distance = B - groupA;
for (int i = ; i < groupA; i++)
{
if (temp > )
{
sb.Append("AA");
if (distance > && B > )
{
sb.Append("BB");
B = B - ;
}
else if (distance <= && B > )
{
sb.Append("B");
B = B - ;
}
else//distance < 0
{
sb.Append("");
}
distance--;
}
else
{
sb.Append("A");
}
temp--;
}
if (freeA != )
{
sb.Append("A");
}
while (B > )
{
sb.Append("B");
B--;
}
return sb.ToString();
} private string Change(string str)
{
str = str.Replace("A", "C");
str = str.Replace("B", "A");
str = str.Replace("C", "B");
return str;
} public string StrWithout3a3b(int A, int B)
{
var result = "";
if (A >= B)
{
result = M1(A, B);
}
else
{
result = M1(B, A);
result = Change(result);
}
return result.ToLower();
}
}

leetcode984的更多相关文章

  1. [Swift]LeetCode984. 不含 AAA 或 BBB 的字符串 | String Without AAA or BBB

    Given two integers A and B, return any string S such that: S has length A + B and contains exactly A ...

随机推荐

  1. [蓝桥杯]ALGO-92.算法训练_前缀表达式

    问题描述 编写一个程序,以字符串方式输入一个前缀表达式,然后计算它的值.输入格式为:“运算符 对象1 对象2”,其中,运算符为“+”(加法).“-”(减法).“*”(乘法)或“/”(除法),运算对象为 ...

  2. 【Zabbix3.0】之入门到精通

    https://www.cnblogs.com/clsn/p/7885990.html 饿了么技术债 http://server.51cto.com/sOS-555999.htm

  3. 【idea】之取消@param注释参数错误提示

    改为

  4. Windows 使用windump进行循环抓包

    准备工作 1.下载tcpdump http://www.winpcap.org/windump/  2.下载WinPcaphttp://www.winpcap.org/install/bin/WinP ...

  5. 基于Kafka消息驱动最终一致事务(二)

    实现用例分析 上篇基于Kafka消息驱动最终一致事务(一)介绍BASE的理论,接着我们引入一个实例看如何实现BASE,我们会用图7显示的算法实现BASE.

  6. 廖雪峰Java1-3流程控制-6 do-while循环

    do-while循环 do-while先执行循环,再判断条件. 条件满足时继续循环:条件不满足时退出:至少循环1次 int sum =0; int n = 1; do{ sum = sum + n; ...

  7. sleep function error ("Advanced Programming in the UNIX Environment" Third Edition No.374)

    测试证明代码: #include <unistd.h> #include <fcntl.h> #include <time.h> #include "ap ...

  8. python的导包问题

    有事会遇到在python代码中导入包错误问题,本文简单对python包的引入做简单介绍 简单说,我认为python导包一共有3种情况,分别是: 要导的包与当前文件在同一层要导的包在当前文件的底层(就是 ...

  9. PHP中常用的数组函数总结

    整理了一份PHP开发中数组操作大全,包含有数组操作的基本函数,数组的分段和填充,数组与栈,数组与列队,回调函数,排序,计算,其他的数组函数等. 一,数组操作的基本函数 数组的键名和值 array_va ...

  10. tf.nn.embedding_lookup

    tf.nn.embedding_lookup(params, ids, partition_strategy=’mod’, name=None, validate_indices=True, max_ ...