题解:层次遍历的基础上加个计数器,偶数层得到的结果反转一下 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeN ...
分类:
其他好文 时间:
2020-07-18 21:52:24
阅读次数:
59
解题:利用队列先进先出来实现层次遍历 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) ...
分类:
其他好文 时间:
2020-07-18 19:52:44
阅读次数:
68
Makefile条件判断 1、示例 下面的例子,判断$(CC)变量是否“gcc”,如果是的话,则使用GNU函数编译目标。 libs_for_gcc = -lgnu normal_libs = foo: $(objects) ifeq ($(CC),gcc) $(CC) -o foo $(object ...
分类:
其他好文 时间:
2020-07-18 19:49:38
阅读次数:
61
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ ...
分类:
其他好文 时间:
2020-07-18 15:54:16
阅读次数:
51
kyu8--fake binary 将小于5的数字用0掩码,大于等于5的用1掩码,用string 下面的答案是高赞的答案。return s.translate(string.maketrans('0123456789', '0000011111')) ...
分类:
其他好文 时间:
2020-07-18 13:46:35
阅读次数:
64
链接:https://leetcode-cn.com/problems/unique-binary-search-trees-ii/ 代码 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNo ...
分类:
其他好文 时间:
2020-07-18 13:39:30
阅读次数:
56
链接:https://leetcode-cn.com/problems/binary-tree-inorder-traversal/ 代码 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNo ...
分类:
其他好文 时间:
2020-07-18 11:34:31
阅读次数:
66
链接:https://leetcode-cn.com/problems/unique-binary-search-trees/ 代码 class Solution { public: int numTrees(int n) { vector<int> f(n + 1); f[0] = 1; for ...
分类:
其他好文 时间:
2020-07-18 11:25:21
阅读次数:
56
此题和之前的剑指offer32-I、II.从上到下打印二叉树大致相同在BFS的基础上只是添加了一个重排序的过程。具体代码如下: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * st ...
分类:
其他好文 时间:
2020-07-18 11:18:07
阅读次数:
58
CF662C Binary Table 题意: 给出一个$n\times m$的$01$矩阵,每次可以反转一行或者一列,问经过若干次反转之后,最少有多少个$1$ \(n\le 20, m\le 10^5\) 题解: 可以把每一列看作一个二进制数,这样得到$m$个二进制数,记为$A$,翻转第$i$列就 ...
分类:
其他好文 时间:
2020-07-18 00:56:09
阅读次数:
87