Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example, If n = 4 and k = 2, a solution is: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ] 方法1:把用queue实现bfs,改为用vector自己实现bfs,没有用额外的内存来存储中间值,但是时间上会Time Limite…
#include <bits/stdc++.h> using namespace std; const int maxn = 55; int ans=0; int vis_Q[maxn]; int book_col[maxn]; int n; bool judge(int r,int c)//能否放在r行c列判断 { if(book_col[c]==1) return false;//如果这列已经被占用,不行 for(int i=1;i<r;i++) { if(abs(c-vis_Q[i…
Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. For example, given a 3-ary tree: We should return its max depth, which is 3. Note: The dept…