Algorithm/LeetCode

[LeetCode] - Find Eventual Safe States

JunGi Jeong 2021. 5. 18. 10:21

 

cycle nodes와 safe nodes를 구분하여 safe nodes를 오름차순으로 반환하라

 

class Solution {
    public List<Integer> eventualSafeNodes(int[][] graph) {
        /*
        n == graph.length
        1 <= n <= 10^4
        0 <= graph[i].length <= n
        graph[i] is sorted in a strictly increasing order
        
        */
        List<Integer> answer = new ArrayList<Integer>();
        int cnt = 0;
        for(int[] arr: graph){
            System.out.print("idx :" + cnt + " items -> ");
            for(int temp : arr){
                System.out.print(temp);
            }
            System.out.println();
            cnt++;
        }
        return answer;
    }
}
상태 파악하기 위한 코드

idx :0 items -> 12
idx :1 items -> 23
idx :2 items -> 5
idx :3 items -> 0
idx :4 items -> 5
idx :5 items -> 
idx :6 items ->