leetcode984
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的更多相关文章
- [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 ...
随机推荐
- python 引用计数
转载:NeilLee(有修改) 一.概述 要保持追踪内存中的对象,Python使用了引用计数这一简单的技术. sys.getrefcount(a)可以查看a对象的引用计数,但是比正常计数大1,因为 ...
- Ubuntu 14.10 下Hadoop 错误集
1 FATAL org.apache.hadoop.ha.ZKFailoverController: Unable to start failover controller. Parent znode ...
- servlet.xml 出现 Referenced file contains errors(http://.......)
问题描述: 打开Eclipse突然发现Web工程的servlet.xml突然报了红叉叉,错误信息如下: Referenced file contains errors (http://www.spri ...
- python "爬虫+有道词典"实现一个简单翻译程序
抓包软件使用的是Fiddler4 新版的查询接口 比较负责,引入了salt和sign http://fanyi.youdao.com/translate?smartresult=dict&sm ...
- PAT 甲级 1006 Sign In and Sign Out (25)(25 分)
1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...
- 学习笔记之Nginx
NGINX | High Performance Load Balancer, Web Server, & Reverse Proxy https://www.nginx.com/ flawl ...
- jquery load()函数和window.onload事件
我想用jquery load()一个饼状图页面, 但是load不出来 代码如下: 后来百度了一下,解决办法如下: window.onload事件只有在文档载入的时候才会执行的,你载入子页面不会触发这个 ...
- centos6.5kvm虚拟化技术
KVM的安装 一.KVM环境配置 1.修改内核模式为兼容内核启动 查看系统内核信息 # uname -a # vi /boot/grub/grub.conf 2.关闭selinux,重启后生效 # v ...
- python之路——6
王二学习python的笔记以及记录,如有雷同,那也没事,欢迎交流,wx:wyb199594 复习 增dic['age'] = 21 dic.setfault()删popcleardel popitem ...
- RHEL7安装图像化桌面
RHEL7安装图像化桌面 作者:Eric 微信:loveoracle11g 在安装系统的时候选择的是默认的Minimal Install RHEL7系统安装完成开机启动后发现没有图形化 Linux系统 ...