ICode9

精准搜索请尝试: 精确搜索
  • leetcode 687 最长同值路径2022-09-06 16:00:45

    给定一个二叉树的 root ,返回 最长的路径的长度 ,这个路径中的 每个节点具有相同值。 这条路径可以经过也可以不经过根节点。 做这道题的时候,我一开始想到的是直接从根节点往下遍历,然后用哈希表记录相同节点出现的次数,然后取出出现次数最多的元素 代码类似这样 public void long

  • 687. 最长同值路径2022-09-02 21:32:17

    687. 最长同值路径 给定一个二叉树的 root ,返回 最长的路径的长度 ,这个路径中的 每个节点具有相同值 。 这条路径可以经过也可以不经过根节点。 两个节点之间的路径长度 由它们之间的边数表示。   示例 1: 输入:root = [5,4,5,1,1,5] 输出:2 示例 2: 输入:root = [1,4,5

  • 687. 最长同值路径2021-12-29 10:34:46

    深度优先搜索 class Solution { int maxLength = 0; public int longestUnivaluePath(TreeNode root) { depth(root); return maxLength; } /** * 在《104. 二叉树的最大深度》的基础上 * 顺便计算以root为起始节点的最长同值路径

  • [cf] Codeforces Round #687 (Div 2)2020-12-02 20:34:48

    Codeforces Round #687 (Div 2) A.Prison Break 水题,直接找4个角,距离出口最远的距离,就是答案 #include <bits/stdc++.h> using namespace std; void file() { #ifdef ONLINE_JUDGE #else freopen( "d:/workProgram/test.txt","r",stdin ); #

  • 「赛后总结」Codeforces Round #687 (Div. 2)2020-11-30 11:01:13

    题意 & 题解 A.Prison Break 题意: 在二维平面中找到距离一个点最大的曼哈顿距离。 题解: 一定在矩阵的四个角上。 #include <cstdio> #include <cstring> #include <string> #include <iostream> #include <algorithm> #define M 100001 #define inf 2147483647 typedef long long

  • Codeforces Round #687 (Div. 2) C2020-11-29 19:01:52

    题意:有一个小球需要从p开始 每次跳k个距离 问条出字符串所用的最短时间; 给一个n, p, k 分别是:字符串长度 ,小球开始位置, 跳跃长度; 再给出字符串,字符串中’1‘表示有一个平台,’0‘表示空地(小球无法从此处跳走) 对字符串有两种操作: 1.将字符串中的某个为'0'的点换成'1' 消耗 x秒 2.

  • LeetCode_6872019-07-25 12:04:30

    class Solution { public: int longestUnivaluePath(TreeNode* root) { if(root == nullptr) return 0; int ans = 0; univalue(root, &ans); return ans; } private: int univalue(TreeNode& root, int* ans) {

  • LeetCode 687. Longest Univalue Path2019-06-21 08:51:15

    原题链接在这里:https://leetcode.com/problems/longest-univalue-path/ 题目: Given a binary tree, find the length of the longest path where each node in the path has the same value. This path may or may not pass through the root. The length of path between two node

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有