Giter Club home page Giter Club logo

Comments (6)

snowan avatar snowan commented on May 5, 2024 1

我添加english version吧?

from leetcode.

3460741663 avatar 3460741663 commented on May 5, 2024

认领

from leetcode.

azl397985856 avatar azl397985856 commented on May 5, 2024

我添加english version吧?

好的啊,我分配给你们两个了

from leetcode.

xiongcaihu avatar xiongcaihu commented on May 5, 2024
/**
 * @param {number[][]} M
 * @return {number}
 * 
 * 首先第一个肯定是一个圈子
 * 然后依次遍历第二个人,第三个人
 * 
 * 每遍历到一个人,都判断它和已经有的圈子的人是否是好友
 * 如果它和多个圈子的人是好友,那么合并多个圈子
 * 
 * 如果不是,那么它自己单独成为一个圈子
 */
var findCircleNum = function (M) {
    var quan = [
        [0]
    ];
    for (var i = 1; i < M.length; i++) {
        var belong = {};
        for (var j = 0; j < quan.length; j++) {
            for (var n = 0; n < quan[j].length; n++) {
                var nowFriend = quan[j][n];
                if (M[i][nowFriend] == 1 || M[nowFriend][i] == 1) {
                    belong[j] = 1;
                    break;
                }
            }
        }
        if (belong.length == 0) {
            quan.push([i]);
        } else {
            var temp = [];
            var newQuan = [];
            quan.forEach((item, index) => {
                if (!belong[index]) {
                    newQuan.push(item);
                } else {
                    temp.push(...item);
                }
            })
            temp.push(i);
            newQuan.push(temp);
            quan = newQuan;
        }
    }
    return quan.length;
};

from leetcode.

azl397985856 avatar azl397985856 commented on May 5, 2024
/**
 * @param {number[][]} M
 * @return {number}
 * 
 * 首先第一个肯定是一个圈子
 * 然后依次遍历第二个人,第三个人
 * 
 * 每遍历到一个人,都判断它和已经有的圈子的人是否是好友
 * 如果它和多个圈子的人是好友,那么合并多个圈子
 * 
 * 如果不是,那么它自己单独成为一个圈子
 */
var findCircleNum = function (M) {
    var quan = [
        [0]
    ];
    for (var i = 1; i < M.length; i++) {
        var belong = {};
        for (var j = 0; j < quan.length; j++) {
            for (var n = 0; n < quan[j].length; n++) {
                var nowFriend = quan[j][n];
                if (M[i][nowFriend] == 1 || M[nowFriend][i] == 1) {
                    belong[j] = 1;
                    break;
                }
            }
        }
        if (belong.length == 0) {
            quan.push([i]);
        } else {
            var temp = [];
            var newQuan = [];
            quan.forEach((item, index) => {
                if (!belong[index]) {
                    newQuan.push(item);
                } else {
                    temp.push(...item);
                }
            })
            temp.push(i);
            newQuan.push(temp);
            quan = newQuan;
        }
    }
    return quan.length;
};

你的命名要笑死我啊

from leetcode.

azl397985856 avatar azl397985856 commented on May 5, 2024

英文版题解: https://github.com/azl397985856/leetcode/blob/master/problems/547.friend-circles-en.md

from leetcode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.