Missing Test Case [Accepted but solution is wrong]


  • 0
    R
    public class Solution {
        public boolean validTree(int n, int[][] edges) {
            Set<Integer> set = new HashSet<>();
            for (int[] edge : edges) {
                if (!set.add(edge[0])) {
                    set.remove(edge[0]);
                }
                if (!set.add(edge[1])) {
                    set.remove(edge[1]);
                }
                if (set.size() == 0) {
                    return false;
                }
            }
            return edges.length == n - 1;
        }
    }
    

    8
    [[1,2],[2,3],[3,4],[4,5],[5,6],[6,3], [6,1]]

    Your answer

    true
    Expected answer

    false


  • 0

    @ratchapong.t Thanks, I have just added your test case.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.