中级农民
- 积分
- 281
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2012-4-19
- 最后登录
- 1970-1-1
|
1361 Validate Binary Tree Nodes
Binary tree, binary tree是不是valid就看edge -1 = nodes
这是错的
还是要用set visited看是不是有reused node
首先要int[] inDegree 如果inDegree的数量>1就false
根据inDegree找出root 如果root > 1 false
dfs遍历这个tree看有没有loop
1129 Shortest Path with Alternating Colors
比较难得BFS
先build一个graph
然后queue里是 Queue<Pair<Integer, Boolean>> qq
boolean代表red或者blue
开始是
qq.add(new Pair<>(0, true));
qq.add(new Pair<>(0, false));
785 Is Graph Bipartite?
BFS, int[] colors
不用build额外的graph 题目中的graph是已经build好的了
不需要set因为有n个点所以用一个int[] colors = new int[n];就可以
完成assign color 比较和看有没有visit过 |
|