LC 984. 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 'a' letters, and exactly B 'b' letters; The substring 'aaa' does not occur in S; The substring 'bbb' does not occur in S. Example 1: Input: A = 1, B…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字符串构造 日期 题目地址:https://leetcode.com/problems/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…
题目如下: Given two integers A and B, return any string S such that: S has length A + B and contains exactly A'a' letters, and exactly B 'b' letters; The substring 'aaa' does not occur in S; The substring 'bbb' does not occur in S. Example 1: Input: A =…
这道题是LeetCode里的第984道题. 题目要求: 给定两个整数 A 和 B,返回任意字符串 S,要求满足: S 的长度为 A + B,且正好包含 A 个 'a' 字母与 B 个 'b' 字母: 子串 'aaa' 没有出现在 S 中: 子串 'bbb' 没有出现在 S 中. 示例 1: 输入:A = 1, B = 2 输出:"abb" 解释:"abb", "bab" 和 "bba" 都是正确答案. 示例 2: 输入:A =…
Given two integers A and B, return any string S such that: S has length A + B and contains exactly A 'a' letters, and exactly B 'b' letters; The substring 'aaa' does not occur in S; The substring 'bbb' does not occur in S. Example 1: Input: A = 1, B…
给定两个整数 A 和 B,返回任意字符串 S,要求满足: S 的长度为 A + B,且正好包含 A 个 'a' 字母与 B 个 'b' 字母: 子串 'aaa' 没有出现在 S 中: 子串 'bbb' 没有出现在 S 中. 示例 1: 输入:A = 1, B = 2 输出:"abb" 解释:"abb", "bab" 和 "bba" 都是正确答案. 示例 2: 输入:A = 4, B = 1 输出:"aabaa&quo…
给定两个整数 A 和 B,返回任意字符串 S,要求满足: S 的长度为 A + B,且正好包含 A 个 'a' 字母与 B 个 'b' 字母: 子串 'aaa' 没有出现在 S 中: 子串 'bbb' 没有出现在 S 中. 示例 1: 输入:A = 1, B = 2 输出:"abb" 解释:"abb", "bab" 和 "bba" 都是正确答案. 示例 2: 输入:A = 4, B = 1 输出:"aabaa&quo…
public static void main(String[] args) { int temp = -1; String[] strs = {"aaa", "ccc", "ddd", "eee", "fff", "ggg"}; for (int i = 0; i < strs.length - 1; i++) { if (strs[i].equals("ccc&quo…
如果是匹配以A开头,以B结尾的内容,同时A和B之间还包含C的这种怎么做?比如 [root@localhost ~]#cat file aaa grge ddd bbb aaa gege ccc bbb aaa gregeg eee bbb 这个中A=aaa,B=bbb,C=ccc,那么要提取出下面的--aaa gegecccbbb [root@localhost ~]#awk '/aaa/{t=1}{if(t)s=length(s)?s"\n"$0:$0}/bbb/{t=0;if(s~…
//导入的包.import java.io.File;import java.io.IOException;//创建的一个类.public class zy { //公共静态的主方法. public static void main(String[] args) throws IOException { //调用方法. zy(); zy2(); } //创建方法. public static void zy() throws IOException { //创建File对象,指定盘符和文件夹名称…
Implement atoi which converts a string to an integer. The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minu…
Given an array of characters, compress it in-place. The length after compression must always be smaller than or equal to the original array. Every element of the array should be a character (not int) of length 1. After you are done modifying the inpu…
上周因为感冒没有刷题,两个星期没有刷题,没手感了,思维也没有那么活跃了,只刷了一道,下个星期努力. 984. 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 'a' letters, and exactly B 'b' letters; The substring 'aaa' does not…
984. 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 'a' letters, and exactly B 'b' letters; The substring 'aaa' does not occur in S; The substring 'bbb' does not occur in…
贪心基础 贪心(Greedy)常用于解决最优问题,以期通过某种策略获得一系列局部最优解.从而求得整体最优解. 贪心从局部最优角度考虑,只适用于具备无后效性的问题,即某个状态以前的过程不影响以后的状态.紧接下来的状态仅与当前状态有关.和分治.动态规划一样,贪心是一种思路,不是解决某类问题的具体方法. 应用贪心的关键,是甄别问题是否具备无后效性.找到获得局部最优的策略.有的问题比较浅显,例如一道找零钱的题目 LeetCode 860. Lemonade Change: // 860. Lemonad…
char 支持的方法 字符串 声明字符串 String str = [null]; 可以用此方法声明一个空字符串   连接字符串 str +"" + str1; 比较两个字符串 Compare 静态方法 返回int 比较两个字符串是否相等,最常用的2个重载方法 Int Compare(string a,string b) Int Compare(string a,string b ,bool ignorCase) 第三方参数是true 忽略大小写 String.Compare(&quo…
String源码:基于jdk1.8 public final class String implements Serializable, Comparable<String>, CharSequence { /** The value is used for character storage. */ private final char[] value; /** Cache the hash code for the string */ private int hash; public St…
当我们在string.Format中传入Json字符串时,会报”输入字符串的格式不正确“,这是因为json的"{"符号的问题,最开始我是想着用转义一下"{",但是转义后我发现原来的非json占位格式缺报错了,因为我破坏了它的占位格式 问题还是没有解决,但是最终从另一个角度解决了我的需求,那就是从把string.Format封装起来,在内部进行判断,如果它的orgs的length为0,那么我们就直接输出format,否则才调用string.Format,一般情况下我们…
一.概述 java的String类可以说是日常实用的最多的类,但是大多数时候都只是简单的拼接或者调用API,今天决定深入点了解一下String类. 要第一时间了解一个类,没有什么比官方的javaDoc文档更直观的了: String类表示字符串.Java程序中的所有字符串文本(如"abc")都作为此类的实例实现. 字符串是常量:它们的值在创建后不能更改.字符串缓冲区支持可变字符串.因为字符串对象是不可变的,所以可以共享它们. 类字符串包括用于检查序列的单个字符.比较字符串.搜索字符串.提…
一.Scanner类 1.api简介: 应用程序编程接口 2.Scanner类: 作用:获取键盘输入的数据 位置: java.util.Scanner. 使用:使用成员方法nextInt() 和 next() 分别接收整型和字符串类型数据 //将Scanner类实例化,并用System.in表示键盘输入 Scanner scanner = new Scanner(System.in); //使用成员方法nextInt() 和next() 分别接收整型和字符串类型数据 int num = scan…
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift    说明:题目中含有$符号则为付费题目. 如:[Swift]LeetCode156.二叉树的上下颠倒 $ Binary Tree Upside Down 请下拉滚动条查看最新 Weekly Contest!!! Swift LeetCode 目录 | Catalog 序        号 题名Title 难度     Difficulty  两数之…
Contest 121 (题号981-984)(2019年1月27日) 链接:https://leetcode.com/contest/weekly-contest-121 总结:2019年2月22日补充的报告.当时不想写.rank:1093/3924,AC:2/4.还是太慢了. [984]String Without AAA or BBB(第一题 4分)(Greedy, M) 给了两个数字,A 代表 A 个 ‘A’, B 代表 B 个‘B’ 在字符串里面.返回一个可行的字符串,字符串中包含 A…
Index : (1)类型语法.内存管理和垃圾回收基础 (2)面向对象的实现和异常的处理 (3)字符串.集合与流 (4)委托.事件.反射与特性 (5)多线程开发基础 (6)ADO.NET与数据库开发基础 (7)WebService的开发与应用基础 一.基础类型和语法 1.1 .NET中所有类型的基类是什么? 在.NET中所有的内建类型都继承自System.Object类型.在C#中,不需要显示地定义类型继承自System.Object,编译器将自动地自动地为类型添加上这个继承申明,以下两行代码的…
Delphi中stringlist分割字符串的用法 TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的. 常规的用法大家都知道,现在来讨论它的一些高级的用法. 1.CommaText 2.Delimiter &DelimitedText 3.Names &Values &ValueFromIndex 先看第一个:CommaText.怎么用呢? const constr :String = 'aaa,bbb,ccc,ddd'; var strs :TStrin…
TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的. 常规的用法大家都知道,现在来讨论它的一些高级的用法. 1.CommaText 2.Delimiter &DelimitedText 3.Names &Values &ValueFromIndex 先看第一个:CommaText.怎么用呢? const constr :String = 'aaa,bbb,ccc,ddd'; var strs :TStrings; i :Integer; begin strs…
一. 命名参数.可选参数 命名参数和可选参数是在Visual C#2010中引入的新特性. 笨地儿我个瓜不兮兮的,今天才知道. 可选参数:定义方法时为参数设置默认值,调用该方法时可以省略为某些形参指定实参. 命名参数:调用方法时,通过指定参数名称的方式为特定形参指定实参.指定时是根据名称将形参和实参关联,而不是与参数在列表中的位置关联. 例如: class Program    {        static void Main(string[] args)        {          …
TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的. 常规的用法大家都知道,现在来讨论它的一些高级的用法. 先把要讨论的几个属性列出来: 1.CommaText 2.Delimiter & DelimitedText 3.Names & Values & ValueFromIndex 先看第一个:CommaText.怎么用呢?用代码说话: const constr :String = 'aaa,bbb,ccc,ddd'; var strs :TStrings…
Delphi TStringList的用法 TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的. TStringList 常用方法与属性: var List: TStringList; i: Integer; begin List := TStringList.Create; List.Add('Strings1'); {添加} List.Add('Strings2'); List.Exchange(0,1); {置换} List.Insert(0,'Strings3')…
import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; public class test1 { /** * @param <JSONObject> * @param args */ public static void main(Stri…
Delphi TStringList的用法 TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的. TStringList 常用方法与属性: var List: TStringList; i: Integer; begin List := TStringList.Create; List.Add('Strings1'); {添加} List.Add('Strings2'); List.Exchange(0,1); {置换} List.Insert(0,'Strings3')…