题解 | #名字串生成I#

名字串生成I

https://www.nowcoder.com/practice/6544721abdd54f1f938f2a98ac03922a

/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 * 
 * @param str1 string字符串 
 * @param str2 string字符串 
 * @return string字符串
 */
function gcdOfStrings(str1, str2) {
    // write code here

    let res = ""

    let str1Length = str1.length
    let str2Length = str2.length

    let str = str1Length > str2Length ? str1 : str2

    for (let i = 1; i < str.length; i++) {
        let subStr = str.slice(0, i)
        if (str.split(subStr).every((item) => item === "")) {
            res = subStr
        }

    }


    return res
}


module.exports = {
    gcdOfStrings: gcdOfStrings
};

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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