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);
    }
}
复制代码

总结:

无官方题解。


相关推荐
呱牛do it3 小时前
企业级门户网站设计与实现:基于SpringBoot + Vue3的全栈解决方案(Day 3)
java·vue
神の愛4 小时前
左连接查询数据 left join
java·服务器·前端
南境十里·墨染春水5 小时前
linux学习进展 线程同步——互斥锁
java·linux·学习
雨奔5 小时前
Kubernetes 联邦 Deployment 指南:跨集群统一管理 Pod
java·容器·kubernetes
杨凯凡5 小时前
【021】反射与注解:Spring 里背后的影子
java·后端·spring
lulu12165440785 小时前
Claude Code项目大了响应慢怎么办?Subagents、Agent Teams、Git Worktree、工作流编排四种方案深度解析
java·人工智能·python·ai编程
riNt PTIP5 小时前
SpringBoot创建动态定时任务的几种方式
java·spring boot·spring
小辉同志5 小时前
215. 数组中的第K个最大元素
数据结构·算法·leetcode··快速选择
老星*6 小时前
AI选股核心设计思路
java·ai·开源·软件开发
それども6 小时前
Comparator.comparing 和 拆箱问题
java·jvm