题解 | #查找兄弟单词#

查找兄弟单词

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("");
}

全部评论

相关推荐

01-29 15:45
已编辑
华中科技大学 前端工程师
COLORSN:可以试一下,小厂看技术栈是不是很落后,如果太拉胯就别去,个人认为有实习氛围比你自己琢磨要高效不少,然后就是小厂其实也有可能会问的很难,这都比较难说,还是看自己项目含金量够不够,寒假还能不能推进学习再选择,毕竟去实习过年就10天假了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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