标签:param push 第一个 code get indexof acs dfa lis
// log
/**
* 找到第一个字母,若没有满足要求的返回null
* @param {string} str
*/
function getFirstCharThatAppearsOnce(str) {
let result
let len = str.length
let blackList = []
for (let i = 0; i < len; i++) {
result = str[i]
if (blackList.indexOf(result) >= 0) {
if (i === len - 1) {
return null
}
continue
}
// test it
for (let j = i + 1; j < len; j++) {
if (result === str[j]) {
blackList.push(result)
break
}
if (j === len - 1) {
return result
}
}
}
}
let x1 = ‘facsdfas22p1dfawsdfasfapsdfdsasdfcnvcviuafawejklnauiyas1‘
let x2 = ‘aabbsdxzcfadzxcsdfa‘
let y1 = getFirstCharThatAppearsOnce(x1)
console.log(y1)
let y2 = getFirstCharThatAppearsOnce(x2)
console.log(y2)
标签:param push 第一个 code get indexof acs dfa lis
原文地址:https://www.cnblogs.com/oceans/p/13588973.html