竞赛讨论区 > 第二题超时
头像
JYeontu
编辑于 2020-08-13 22:56
+ 关注

第二题超时

第二题只过了80%,后面超时,求解要用什么方法(有js的吗?)
function solve( str ) {
            var res = str;
            var result = "";
            var a = res.indexOf("00"),b = res.indexOf("11");
            while(a != -1 || b != -1){
                if(a != -1 && (a < b || b == -1)){
                    var a1 = res.substring(0,a);
                    var a2 = res.substring(a+2);
                    res = a1 + "1" + a2;
                }
                else{
                    var a1 = res.substring(0,b);
                    var a2 = res.substring(b+2);
                    res = a1 + a2;
                }
                a = res.indexOf("00"),b = res.indexOf("11");
            }
            return res;
        }

全部评论

(0) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐