{"size": 519, "ext": "js", "max_stars_repo_path": "solutions/687.longest-univalue-path/longest-univalue-path.js", "max_stars_repo_name": "wangsongiam/leetcode", "max_stars_repo_stars_event_min_datetime": "2018-11-25T15:19:57.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-28T03:01:11.000Z", "max_issues_repo_path": "solutions/687.longest-univalue-path/longest-univalue-path.js", "max_issues_repo_name": "casprwang/leetcode", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "solutions/687.longest-univalue-path/longest-univalue-path.js", "max_forks_repo_name": "casprwang/leetcode", "max_forks_repo_forks_event_min_datetime": "2018-02-11T20:23:44.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-05T15:39:56.000Z"}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": 3, "avg_line_length": 16.21875, "max_line_length": 52, "alphanum_fraction": 0.5086705202}

const longestUnivaluePath = root => {
  let max = 0

  const dfs = node => {
    if (node === null) return 0
    let left = dfs(node.left)
    let right = dfs(node.right)

    // let llen = 0
    // let rlen = 0

    if (node.left && node.val === node.left.val) {
      left++
    } else {
      left = 0
    }

    if (node.right && node.val === node.right.val) {
      right++
    } else {
      right = 0
    }

    max = Math.max(max, left + right)
    return Math.max(left, right)
  }

  dfs(root)
  return max
}
