leetcode每日一题——51
public static List<List<String>> solveNQueens(int n) {
List<List<String>> res =new ArrayList<>();
if(n<=0) return res;
helper(res,new int [n],0);
return res;
}
private static void helper(List<List<String>> res, int[] queen, int pos) {
if(pos==queen.length) {
addsolution(res,queen);
return ;
}
for (int i = 0; i < queen.length; i++) {
queen[pos]=i;
if (isvalid(queen,pos)) {
helper(res, queen, pos+1);
}
}
}
private static boolean isvalid(int queen[],int pos) {
for (int i = 0; i < queen.length; i++) {
if (queen[i]==queen[pos]) {
return false;
}else if (Math.abs(queen[pos]-queen[i])==Math.abs(i-pos)) {
return false;
}
}
return true;
}
超出字数了。。。。。。
public static List<List<String>> solveNQueens(int n) {
List<List<String>> res =new ArrayList<>();
if(n<=0) return res;
helper(res,new int [n],0);
return res;
}
private static void helper(List<List<String>> res, int[] queen, int pos) {
if(pos==queen.length) {
addsolution(res,queen);
return ;
}
for (int i = 0; i < queen.length; i++) {
queen[pos]=i;
if (isvalid(queen,pos)) {
helper(res, queen, pos+1);
}
}
}
private static boolean isvalid(int queen[],int pos) {
for (int i = 0; i < queen.length; i++) {
if (queen[i]==queen[pos]) {
return false;
}else if (Math.abs(queen[pos]-queen[i])==Math.abs(i-pos)) {
return false;
}
}
return true;
}
超出字数了。。。。。。
全部评论
相关推荐
烤点老白薯:大厂的正式测试开发工程师已经要变成全栈或者agent的开发工程师,或者说是什么AI体验 AI质量工程师了。然后那种最低级的外包测试岗应该还是有岗位的,不过正式员工肯定是要求会越来越高了 点赞 评论 收藏
分享