LCP 44.开幕式焰火

​​题目来源:

leetcode题目,网址:LCP 44. 开幕式焰火 - 力扣(LeetCode)

解题思路:

遍历并计数即可。

解题代码:

复制代码
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    public int numColor(TreeNode root) {
        Set<Integer> set=new HashSet<>();
        count(root,set);
        return set.size();
    }
    public void count(TreeNode root, Set<Integer> set){
        if(root==null){
            return ;
        }
        set.add(root.val);
        count(root.left,set);
        count(root.right,set);
    }
}
复制代码

总结:

无官方题解。


相关推荐
Tim_1014 分钟前
【C++】009、extern关键字
java·开发语言
ShiXZ21317 分钟前
PDF-OCR文件识别篇(七):数据入库
java·pdf·json·ocr·springboot
rebibabo1 小时前
Java基础(番外) | Kafka 入门:分区、副本与消费者组原理
java·分布式·kafka·学习笔记·副本·分区·异步日志
Flittly1 小时前
【AgentScope Java新手村系列】(17)长期记忆系统
java·spring boot·spring
wei1986211 小时前
.net添加web引用和添加服务引用有什么区别?
java·前端·.net
Full Stack Developme1 小时前
正则表达式的使用教程
java·数据库·正则表达式
SeeYa-J2 小时前
Sprint 1-2:创建第一个 Spring Boot Module(user-service)
java·spring boot·sprint
郭梧悠2 小时前
算法:有效的括号
python·算法·leetcode
旖-旎2 小时前
《LeetCode 1137 第N个泰波那契数 和 LeetCode 三步问题》
c++·算法·leetcode·动态规划