public int findNQueens(int [] locations, int row) {
        if (row == locations.length) {
            //printNQueens(locations);
            return 1;
        }

        int result = 0;
        for(int i=0; i<locations.length; i++) {
            if (check(locations, row, i)) {
                locations[row] = i;
                result += findNQueens(locations, row+1);
            }
        }
        return result;
    }