题解 | #字符串的排列#

字符串的排列

https://www.nowcoder.com/practice/fe6b651b66ae47d7acce78ffdd9a96c7

function Permutation(str)
{
    // write code here
    if (str.length <= 1) return [str]
    const result = []
    const items = str.split('')
    const current = items.shift()
    const subResult = Permutation(items.join(''))
    for (let i = 0; i <= items.length; i++) {
        for (let j = 0; j < subResult.length; j++) {
            const currentSubItem = subResult[j].split('')
            currentSubItem.splice(i, 0, current)
            const currentStr = currentSubItem.join('')
            result.push(currentStr)
        }
    }
    const res = new Set(result)
    return Array.from(res)
}
module.exports = {
    Permutation : Permutation
};

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 18:19
个个985的硕士闭着眼睛都有15k以上的月薪,天天嚷嚷着研究生白度读了,天天嚷嚷着反向读研了........
MMMJC:不读研22本科出去的基本都拿28k呢,你不能用25的研究生和25的本科生比然后说没反向读研,而是25研和22本比呀
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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