Leetcode no. 52
来源:互联网 发布:popo聊天软件 编辑:程序博客网 时间:2024/04/30 13:01
52. N-Queens II
Follow up for N-Queens problem.
Now, instead outputting board configurations, return the total number of distinct solutions.
public class Solution { int count=0; public int totalNQueens(int n){ solveNQueens(0, 0, n, new int[n]); return count; } private void solveNQueens(int row, int col, int n, int[] column){ if (row == n) count++; else{ for (int i = col; i < n; i++) { column[row]= i; boolean f= true; for (int r = row-1, lc= i-1, rc= i+1; r>=0 ; r--,lc--,rc++ ) { if (column[r]== i || column[r]==lc || column[r]==rc) f= false; } if (f) solveNQueens(row+1, 0, n, column); } } }}
0 0
- Leetcode no. 52
- LeetCode No.52 N-Queens II
- LeetCode No.11 ~No.12
- Leetcode NO.78 Subsets
- Leetcode NO.77 Combinations
- Leetcode NO.46 Permutations
- 【leetcode】No. 235 LCABST
- LeetCode no. 35
- Leetcode no. 37
- Leetcode no. 279
- Leetcode no. 335
- Leetcode no. 283
- Leetcode no. 181 (sql)
- Leetcode no. 40
- Leetcode no. 238
- Leetcode no. 26
- Leetcode no. 80
- Leetcode no. 228
- 分布式架构高可用架构篇_01_zookeeper集群的安装、配置、高可用测试
- 翻译_Understanding JSON(理解json)
- Intuition of Back Propogation&Sparse Autoencoder
- Jackson学习笔记(一)
- 安卓006单元测试
- Leetcode no. 52
- MySQL数据库引擎详解
- 模仿音乐播放器项目
- 数据挖掘基本知识框架
- 初识html5基本格式
- 笔试题24. LeetCode OJ (11)
- vs2010删除类
- 判断大端还是小端
- 十个随机数求和 一