Algorithm
还是先做easy的找找感觉
- N-ary Tree Level Order Traversal
遍历N叉树并按层级输出。
这题比较简单,可以用队列。
/*
// Definition for a Node.
class Node {
public int val;
public List children;
public Node() {}
public Node(int _val,List _children) {
val = _val;
children = _children;
}
};
*/
class Solution {
public List> levelOrder(Node root) {
List> res = new ArrayList>();
if (root == null) {
return res;
}
Queue queue = new LinkedList();
queue.offer(root);
queue.offer(null);
List list = new ArrayList();
while (queue.size() > 0) {
Node node = queue.poll();
if (node == null) {
res.add(list);
if (queue.size() > 0) {
list = new ArrayList();
queue.offer(null);
}
}
if (node != null) {
list.add(node.val);
if (node.children != null && node.children.size() > 0) {
queue.addAll(node.children);
}
}
}
return res;
}
}
Review
https://www.javaworld.com/article/3268983/java-challengers-1-method-overloading-in-the-jvm.html
小结:
在JVM处理重载时,有三个重要的编译技术:Widening; Boxing; Varargs
Widening
示例:
int primitiveIntNumber = 5;
double primitiveDoubleNumber = primitiveIntNumber ;
较低等级的类型会自动扩展为较高等级的类型
Boxing
基础类型可以box为包装类型;包装类型也可以unbox为基础类型
int primitiveIntNumber = 7;
Integer wrapperIntegerNumber = primitiveIntNumber;
Integer wrapperIntegerNumber = Integer.valueOf(primitiveIntNumber);
Varargs
利用...来表示多个传入参数,在无法获知具体传入参数个数时可以使用
注意
- int基础类型无法autobox为Double而只能autobox为double
- Integer Long Float Double这些无法相互扩展
- 硬编码时,JVM会自动将1编译为int,将1.0编译为double。可以用1F来表示float,1D来表示double,增加可读性
- Double类型更容易被包装为Object,而不是被unbox为double
- JVM执行顺序:Widening----->Boxing----->Varargs
Tip
- 如何在idea中搜寻文件---双击shift
- 挑选出表table中userId计数大于1的所有内容
Select * From table Where userId In (Select userId From table Group By userId Having Count(*)>1)