Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1/22 HTTP + 네트워크 #41

Open
skarltjr opened this issue Jan 22, 2021 · 0 comments
Open

1/22 HTTP + 네트워크 #41

skarltjr opened this issue Jan 22, 2021 · 0 comments
Labels

Comments

@skarltjr
Copy link
Owner

package algo;


import java.util.*;

public class Solution {
    int current = 0;
    public int solution(int n, int[][] computers)
    {
        Set<Integer> count = new HashSet<>();
        int[] record = new int[n];
        for (int i = 0; i < n; i++)
        {
            record[i] = -1;
        }


        for (int i = 0; i < n; i++)
        {
            search(i,computers,record);
            current++;
        }


        for (int i = 0; i < n; i++) {
            if (record[i] != -1)
            {
                count.add(record[i]);
            }
        }

        return count.size();
    }

    public void search(int index,int[][] computers,int[] record)
    {
        for (int i = 0; i < computers[index].length; i++)
        {
            //연결이되어있으면
            if (computers[index][i] == 1 && record[i]==-1) {
                record[i] = current;
                if (i != index)
                {
                    search(i,computers,record);
                }
            }
        }
    }



}


@skarltjr skarltjr added the Daily label Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant