Home
  • 计算机网络
  • 操作系统
  • 数据结构与算法
  • 设计模式
  • JavaSE
  • JVM
  • JUC
  • Netty
  • CPP
  • QT
  • UE
  • Go
  • Gin
  • Gorm
  • HTML
  • CSS
  • JavaScript
  • vue2
  • TypeScript
  • vue3
  • react
  • Spring
  • SpringMVC
  • Mybatis
  • SpringBoot
  • SpringSecurity
  • SpringCloud
  • Mysql
  • Redis
  • 消息中间件
  • RPC
  • 分布式锁
  • 分布式事务
  • 个人博客
  • 弹幕视频平台
  • API网关
  • 售票系统
  • 消息推送平台
  • SaaS短链接系统
  • Linux
  • Docker
  • Git
GitHub (opens new window)
Home
  • 计算机网络
  • 操作系统
  • 数据结构与算法
  • 设计模式
  • JavaSE
  • JVM
  • JUC
  • Netty
  • CPP
  • QT
  • UE
  • Go
  • Gin
  • Gorm
  • HTML
  • CSS
  • JavaScript
  • vue2
  • TypeScript
  • vue3
  • react
  • Spring
  • SpringMVC
  • Mybatis
  • SpringBoot
  • SpringSecurity
  • SpringCloud
  • Mysql
  • Redis
  • 消息中间件
  • RPC
  • 分布式锁
  • 分布式事务
  • 个人博客
  • 弹幕视频平台
  • API网关
  • 售票系统
  • 消息推送平台
  • SaaS短链接系统
  • Linux
  • Docker
  • Git
GitHub (opens new window)
  • 哈希表

  • 双指针

  • 数组

  • 字符串

  • 链表

  • 树

  • 回溯

  • 动态规划

  • 图

  • 二分查找

  • 贪心

  • 栈&队列

  • 堆

  • 位运算

  • 数据结构设计

  • rui的精选题单

  • 笔试真题

  • LeetCode周赛

    • 第380场周赛
    • 第381场周赛
    • 第382场周赛
      • 3020. 子集中元素的最大数量
  • ACM模式输入输出
  • 数学

  • 数据结构与算法
  • LeetCode周赛
Nreal
2024-02-07
目录

第382场周赛

# 3020. 子集中元素的最大数量 (opens new window)

class Solution {
    public int maximumLength(int[] nums) {
        Map<Long,Integer> cnt = new HashMap<>();
        for(int num:nums){
            cnt.merge((long) num,1,Integer::sum);
        }
        Integer c = cnt.remove(1L);// 移除1
        int ans = c!=null? c-(c%2^1):0;// 保证奇数个
        for(long x:cnt.keySet()){
            int res = 0;
            for( ;cnt.getOrDefault(x,0)>1;x*=x){
                res+=2;
            }
            // x^k是 单独一个
            ans = Math.max(ans,res+(cnt.containsKey(x)?1:-1));
        }
        return ans;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
第381场周赛
ACM模式输入输出

← 第381场周赛 ACM模式输入输出→

Theme by Vdoing | Copyright © 2021-2024
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式