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

总结:

无官方题解。


相关推荐
014-code14 分钟前
订单超时取消与库存回滚的完整实现(延迟任务 + 状态机)
java·开发语言
java1234_小锋1 小时前
Java高频面试题:Springboot的自动配置原理?
java·spring boot·面试
末央&2 小时前
【天机论坛】项目环境搭建和数据库设计
java·数据库
枫叶落雨2222 小时前
ShardingSphere 介绍
java
花花鱼2 小时前
Spring Security 与 Spring MVC
java·spring·mvc
小白菜又菜3 小时前
Leetcode 2075. Decode the Slanted Ciphertext
算法·leetcode·职场和发展
言慢行善3 小时前
sqlserver模糊查询问题
java·数据库·sqlserver
专吃海绵宝宝菠萝屋的派大星3 小时前
使用Dify对接自己开发的mcp
java·服务器·前端
大数据新鸟3 小时前
操作系统之虚拟内存
java·服务器·网络
Tong Z3 小时前
常见的限流算法和实现原理
java·开发语言