LeetCode - 942. 增减字符串匹配
作者:互联网
奇怪了,同样的代码第一遍运行出错了…
/**
* @param {string} S
* @return {number[]}
*/
var diStringMatch = function(S) {
let len = S.length;
let ret = []
let low = 0
let a = S.split('')
a.forEach(char => {
if(char === 'I'){
ret.push(low)
low ++
}else{
ret.push(len)
len --
}
})
ret.push(a[a.length-1] === 'I' ? len : low)
return ret
};
标签:942,len,char,push,let,ret,字符串,LeetCode,low 来源: https://blog.csdn.net/csu_passer/article/details/89972444