My accepted solution.No need to reverse string.


  • 1
    S
    var findPermutation = function(word) {
        if(!word){
            return;
        }
        var res=[];
        var i=1;
        res.push(i);
        var dInsert=0;
        word.split('').forEach(e=>{
           if(e==='D'){
               res.splice(dInsert,0,++i);
           } else if(e==='I'){
               res.push(++i);
               dInsert=res.length-1;
           }
        });
        return res;
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.