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

总结:

无官方题解。


相关推荐
OtIo TALL5 小时前
redis7 for windows的安装教程
java
uNke DEPH6 小时前
Spring Boot的项目结构
java·spring boot·后端
xixingzhe26 小时前
idea启动vue项目
java·vue.js·intellij-idea
wzl202612136 小时前
企业微信定时群发技术实现与实操指南(原生接口+工具落地)
java·运维·前端·企业微信
凌波粒6 小时前
Java 8 “新”特性详解:Lambda、函数式接口、Stream、Optional 与方法引用
java·开发语言·idea
曹牧6 小时前
Eclipse:悬停提示(Hover)
java·ide·eclipse
oyzz1207 小时前
Spring EL 表达式的简单介绍和使用
java·后端·spring
iNgs IMAC7 小时前
Redis之Redis事务
java·数据库·redis
程序员小假7 小时前
向量检索的流程是怎样的?Embedding 和 Rerank 各自的作用?
java·后端
阿Y加油吧8 小时前
算法实战笔记:LeetCode 169 多数元素 & 75 颜色分类
笔记·算法·leetcode