Inspired to Write

I really enjoy writing, but I tend to write in spurts. I will get very active for a few days and then I put down my (digital) pen and paper and just walk away for a week or 20. I started writing a…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




863. All Nodes Distance K in Binary Tree

Medium

Description

Given the root of a binary tree, find the maximum value V for which there exists different nodes A and B where V = |A.val - B.val| and A is an ancestor of B.

(A node A is an ancestor of B if either: any child of A is equal to B, or any child of A is an ancestor of B.)

Example 1:

Note:

找出這條路的最大最小值, 可以不用在每一次都算一次. 走到leaf算一次就可以了

以下寫法稍微精簡一點.

Add a comment

Related posts:

How Educators Have Supported Preschool Children in Minnesota

Debra has been a parent educator for over 30 years. She holds the title ELS, which is Early Learning Services, and ECFE, which is Early Childhood Family Education. She has an early childhood license…

For Her

Ainda lembra como nos conhecemos? O nosso primeiro e último encontro. Dia a pós dias depois daquela noite em que te ouvi refletir, cantar, jogar ping pong e depois… dançar. Fui notando o quão ficava…

Leverage an experience vision to become a market leader

Developing a product or service that stands out from the competition is hard. What is worse, with any successful product launch the competition quickly emerges. Each company is trying to grow their…