Why can't this code be accepted?


  • -1
    Y
    I can run this code by getting a correct result. But cant submit. Anyone knows?
    

    public class Solution {
    static int total=0;
    static HashSet<Integer> col;
    static HashSet<Integer> d1;
    static HashSet<Integer> d2;

    public void dfs(int row, int n){
        if(row==n){
            total++;
            return;
        }
        for(int i=0; i<n; i++){
            if(col.contains(i) || d1.contains(row+i) || d2.contains(row-i) ) continue;
            
            col.add(i);
            d1.add(row+i);
            d2.add(row-i);
            
            dfs(row+1,n);
            
            col.remove(i);
            d1.remove(row+i);
            d2.remove(row-i);
        }
    }
    public int totalNQueens(int n) {
        col=new HashSet<>();
        d1=new HashSet<>();
        d2=new HashSet<>();
        
        dfs(0,n);
        return total;
        
    }
    

    }


Log in to reply
 

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