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

总结:

无官方题解。


相关推荐
Gofarlic_oms17 分钟前
Adams许可排队严重?不想买新许可,闲置回收立即可用
java·大数据·服务器·开发语言·人工智能
mask哥9 分钟前
15种算法模式java实现详解
java·算法·力扣
大大杰哥17 分钟前
leetcode hot100(2)双指针,滑动窗口
数据结构·算法·leetcode
skilllite作者17 分钟前
GEO 是什么:从搜索引擎到「对话式答案」的信息可见性
java·前端·笔记·安全·搜索引擎·agentskills
是宇写的啊20 分钟前
SpringBoot 统一功能处理
java·spring boot·后端
风筝在晴天搁浅20 分钟前
LeetCode CodeTop 113.路径总和Ⅱ
算法·leetcode
等....22 分钟前
Spring Boot多模块项目部署
java·spring boot·后端
水木流年追梦25 分钟前
【python因果库实战26】逆概率加权模型1
开发语言·python·算法·leetcode
SiYuanFeng36 分钟前
面试大厂leetcode重点题型简洁明快复习(dfs/bfs,动态规划,链表,滑动窗口/双指针,回溯,ACM型输入输出,二分)
leetcode·面试·coding
斌果^O^37 分钟前
SpringBoot 实战:@Async + CompletableFuture 实现多 SQL 并行统计查询
java·spring boot·sql