1026. Maximum Difference Between Node and Ancestor
1 | class Solution { |
就是到达某个node时, 我们需要告诉它, 它的ancestors的最大值和最小值是多少. 然后和最大值最小值做差取绝对值, 看哪个大, 大的那个就是该node能凑成的最大的值.
时间复杂度: O(n)
空间复杂度: O(n)
Insist on doing small things, then witness the magic
1 | class Solution { |
就是到达某个node时, 我们需要告诉它, 它的ancestors的最大值和最小值是多少. 然后和最大值最小值做差取绝对值, 看哪个大, 大的那个就是该node能凑成的最大的值.
时间复杂度: O(n)
空间复杂度: O(n)