leetcode 98:n-queens-ii
题目描述

Now, instead outputting board configurations, return the total number of distinct solutions.

输出
class Solution {
public:
/**
*
* @param n int整型
* @return int整型
*/
void f(int &cnt,int a[],int n,int level){
if (level ==n) {cnt++;return;}
for (int i=0;i<n;i++){
int j=0;
for (;j<level;j++){
if (a[j]==i || level -j ==i-a[j] || j-level==i-a[j]) break;
}
if (j==level){
a[level]=i;
f(cnt,a,n,level+1);
}
}
}
int totalNQueens(int n)
{
int a[n];
int cnt=0;
f(cnt,a,n,0);
return cnt;
}
};
leetcode 98:n-queens-ii的更多相关文章
- LeetCode Single Number I / II / III
[1]LeetCode 136 Single Number 题意:奇数个数,其中除了一个数只出现一次外,其他数都是成对出现,比如1,2,2,3,3...,求出该单个数. 解法:容易想到异或的性质,两个 ...
- [array] leetcode - 40. Combination Sum II - Medium
leetcode - 40. Combination Sum II - Medium descrition Given a collection of candidate numbers (C) an ...
- LeetCode 137. Single Number II(只出现一次的数字 II)
LeetCode 137. Single Number II(只出现一次的数字 II)
- LeetCode:路径总和II【113】
LeetCode:路径总和II[113] 题目描述 给定一个二叉树和一个目标和,找到所有从根节点到叶子节点路径总和等于给定目标和的路径. 说明: 叶子节点是指没有子节点的节点. 示例:给定如下二叉树, ...
- LeetCode:组合总数II【40】
LeetCode:组合总数II[40] 题目描述 给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. candi ...
- [Leetcode] n queens ii n皇后问题
Follow up for N-Queens problem. Now, instead outputting board configurations, return the total numbe ...
- [Leetcode][Python]52: N-Queens II
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 52: N-Queens IIhttps://oj.leetcode.com/ ...
- [LeetCode] Number of Islands II 岛屿的数量之二
A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand oper ...
- LeetCode:Word Ladder I II
其他LeetCode题目欢迎访问:LeetCode结题报告索引 LeetCode:Word Ladder Given two words (start and end), and a dictiona ...
- LeetCode:Path Sum I II
LeetCode:Path Sum Given a binary tree and a sum, determine if the tree has a root-to-leaf path such ...
随机推荐
- 多测师讲解自动化测试 _接口面试题(001)_高级讲师肖sir
1.为什么要做接口测试(必要性)1.可以发现很多在页面上操作发现不了的bug2.检查系统的异常处理能力3.检查系统的安全性.稳定性4.前端随便变,接口测好了,后端不用变5.可以测试并发情况,一个账号, ...
- day52 Pyhton 前端03
内容回顾 块级标签: div p h 列表:ol;ul;dl 表格:table 行内标签: span a i/em b/strong u/del 行内块: input textarea img 其他: ...
- C++字符串操作小结
忽略大小写比较大小 库函数strcasecmp和_stricmp: 这两个函数都不属于C++标准库,strcasecmp由POSIX引入,windows平台则定义了功能等价的_stricmp.用法和C ...
- 经验分享:Windows10值得推荐的软件,总有一款是你的菜
今天在知乎上看到有人分享wids10推荐好用的软件:今天小编做了一点点的修改和根据自己的使用情况总结出来转发分享给大家: 1.安全放病毒--火绒[推荐] 2.办公软件--office2019[推荐 ...
- lumen容器模仿
<?php class Container { private $bindings = []; private $instances = []; public function getClosu ...
- lumen laravel response对象返回数据
Route::get('home', function () { $content = "内容"; $status = 301; $value = 'text/html'; // ...
- 后羿:我射箭了快上—用MotionLayout实现王者荣耀团战
前言 昨晚跟往常一样,饭后开了一局王者荣耀,前中期基本焦灼,到了后期一波决定胜负的时候,我果断射箭,射中对面,配合队友直接秒杀,打赢团战一波推完基地.那叫一个精彩,队友都发出了666666的称赞,我酷 ...
- Jira 8.5.1 安装教程
Jira安装教程 一.CentOS设置 1. 更换阿里源 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/rep ...
- springboot添加拦截器
一,编写拦截器 public class TokenInterceptor implements HandlerInterceptor { @Override public boolean preHa ...
- Stream(三)
public class Test08 { /* * 二.中间的加工操作 * (1)filter(Predicate p):过滤 * (2)distinct():去重 * (3)limit(long ...