LeetCode 1372. Longest ZigZag Path in a Binary Tree二叉树中的最长交错路径【Medium】【Python】【DFS】 Problem LeetCode Given a binary treeroot, a ZigZag path for a binary tree is defined as follow: Chooseanynode in th
Can you solve this real interview question? Longest ZigZag Path in a Binary Tree - You are given the root of a binary tree. A ZigZag path for a binary tree is defined as follow: * Choose any node in the binary tree and a direction (right or left). *
噫DFS好,用一个boolean控制向左向右,二叉树还是太菜了我 https://leetcode.com/problems/longest-zigzag-path-in-a-binary-tree/discuss/534418/Java-DFS-Solution-with-comment-O(N)-Clean-code
Given a binary treeroot, a ZigZag path for a binary tree is defined as follow: Choose any node in the binary tree and a direction (right or left). If the current direction is right then move to the right child of the current node otherwise move to the left child. Change the direction...
package leetcode import ( "github.com/halfrost/leetcode-go/template" ) // 解法一 map,时间复杂度 O(n) func longestConsecutive(nums []int) int { res, numMap := 0, map[int]int{} for _, num := range nums { if numMap[num] == 0 { left, right, sum := 0, 0, 0 if numMap...
leetcode 题解,记录自己的 leetcode 解题之路。 本仓库目前分为五个部分: 第一个部分是 leetcode 经典题目的解析,包括思路,关键点和具体的代码实现。 第二部分是对于数据结构与算法的总结 第三部分是 anki 卡片, 将 leetcode 题目按照一定的方式记录在 anki 中,方便大家记忆。