无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

LeetCode 984. String Without AAA or BBB

2023-05-21 09:29 作者:您是打尖兒還是住店呢  | 我要投稿

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, and

  • The substring?'bbb'?does not occur in?s.

?

Example 1:

Input: a = 1, b = 2Output: "abb"Explanation: "abb", "bab" and "bba" are all correct answers.

Example 2:

Input: a = 4, b = 1Output: "aabaa"

?

Constraints:

  • 0 <= a, b <= 100

  • It is guaranteed such an?s?exists for the given?a?and?b.

給定2個(gè)數(shù)字,然后如何組成字符串使得不能出現(xiàn)3個(gè)連續(xù)相同的字符,但是一定有這種滿足題目的組合,

所以我們就去判斷a跟b的大小,如果a>b 這時(shí)候分兩種情況,一種是a>2b的時(shí)候,這時(shí)候依次去添加aab,剩下的時(shí)候添加ab,最后a肯定還有多的,然后去添加剩下的a。

b>a的時(shí)候是相同的規(guī)則,依次去判斷即可。


Runtime:?0 ms, faster than?100.00%?of?Java?online submissions for?String Without AAA or BBB.

Memory Usage:?40 MB, less than?74.00%?of?Java?online submissions for?String Without AAA or BBB.


LeetCode 984. String Without AAA or BBB的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
铜梁县| 化隆| 龙南县| 临澧县| 博白县| 武城县| 二手房| 来凤县| 阿坝县| 勐海县| 洛南县| 石河子市| 柏乡县| 阿坝县| 大丰市| 淮南市| 曲阜市| 禹城市| 任丘市| 沅陵县| 岳阳市| 青阳县| 晋州市| 富民县| 谷城县| 望奎县| 新竹市| 兴业县| 宜兰县| 哈密市| 邓州市| 抚顺县| 康定县| 策勒县| 高邑县| 大冶市| 印江| 博爱县| 镇远县| 灯塔市| 隆昌县|