Similarity of Subtrees Define the depth of a node in a rooted tree by applying the following rules recursively: The depth of a root node is 0. The depths of child nodes whose parents are with depth d are d+1 . Let S(T,d) be the number of nodes of T w…
2016弱校联盟十一专场10.3 传送门 B. Help the Princess! 计算皇后和士兵谁先到达出口即可. C. We don't wanna work! 两个优先队列维护工作中积极性最小的,空闲中积极性最高的. 两个队列倒来倒去就可以了. D. Parentheses 考虑最坏情况)))...(((. 假设有\(x\)个右括号,那么这种情况需要\(\frac{x(x+1)}{2}\)次操作. 将第一个左括号移动每往左移动一个位置,则需要的操作次数减一,直到移动到最左边则变成\(x-…
Given a binary tree, count the number of uni-value subtrees. A Uni-value subtree means all nodes of the subtree have the same value. For example:Given binary tree, 5 / \ 1 5 / \ \ 5 5 5 return 4. 这道题让我们求相同值子树的个数,就是所有节点值都相同的子树的个数,之前有道求最大BST子树的题Largest…
Cosine similarity is a measure of similarity between two non zero vectors of an inner product space that measures the cosine of the angle between them. The cosine of 0° is 1, and it is less than 1 for any other angle. It is thus a judgment of orienta…