题解 | #字符串排序#

字符串排序

http://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584

const line = readline()
const LEN = line.length
const nums = []
const others = []
let arr = new Array(26).fill('')
let res = ''
for(let i = 0; i < LEN; i++){
    let codeValue = line[i].charCodeAt()
    if((codeValue >= 65 && codeValue <= 90) || (codeValue >= 97 && codeValue <= 122)){
        arr[line[i].toLowerCase().charCodeAt() - 97] += line[i] 
    }else{
        others.push(line[i])
        nums.push(i)
    }
}
others.reverse()
arr = arr.join('').split('')

for(let i = 0; i <LEN; i++){
    if(nums.includes(i)){
        res+=others.pop()
    }else{
        res+=arr.shift()
    }
}
console.log(res)
全部评论

相关推荐

程序员牛肉:你这简历有啥值得拷打的?在牛客你这种简历一抓一大把,也就是个人信息不一样而已。 关键要去找亮点,亮点啊,整个简历都跟流水线生产出来的一样。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务