首页 > 试题广场 >

01游戏

[编程题]01游戏
  • 热度指数:1138 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
对01字符串进行一些操作,01字符串上的0和0相邻时会变成1,而1和1相邻时会在字符串上消失,而0和1相邻时什么都不会发生,问这个字符串最后会变成什么样。

示例1

输入

"00110001"

输出

"01"

说明

00110001→1110001→10001→1101→01  

备注:
,字符串上的合并消失应优先与左边进行,例如000,中间的0优先与左边的0合并变为10,消失同理
头像 诗云panther
发表于 2021-08-14 20:59:58
class Solution: def solve(self, str): li = list(str) oli = [] i = 0 for i in range(0, len(li)): if not oli: 展开全文
头像 牛客516598323号
发表于 2020-09-04 14:42:50
404_boy的解法python3实现. class Solution: def solve(self, str): li = list(str) oli = [] i = 0 for i in range(0, len(li) 展开全文