题解 | #查找兄弟单词#

查找兄弟单词

https://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    // Write your code here
    while(line = await readline()){
        const inputs = line.split(" ");
        const n = inputs[0]
        const words = inputs.slice(1, n+1)
        const x = inputs.at(-2)
        const k = inputs.at(-1)

        const bros = []
        for (const w of words) {
            if (isBro(w, x)) {
                bros.push(w);
            }
        }
        console.log(bros.length);
        if (bros.length > k - 1) {
            bros.sort();
            console.log(bros[k-1])
        }
    }
}()

function isBro(a, b) {
    if (a.length !== b.length) {
        return false
    }
    if (a === b) {
        return false
    }
    return a.split("").sort().join("") === b.split("").sort().join("");
}

全部评论

相关推荐

03-31 18:02
门头沟学院 Java
白日梦想家_等打包版:不要的哦佛给我
点赞 评论 收藏
分享
03-07 13:32
门头沟学院 C++
未来可欺a:读研吧,这简历只适合学历高的,本科大概率只能干开发,你这个简历开发不匹配,算法和深度学习的话学历又不够
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务