当前位置:网站首页>[brother hero July training] day 21: the smallest number in infinite concentration
[brother hero July training] day 21: the smallest number in infinite concentration
2022-07-22 11:30:00 【If I were Wen Shuai】
Series articles
【 Brother hero training in July 】 The first 01 God : Array
【 Brother hero training in July 】 The first 02 God : character string
【 Brother hero training in July 】 The first 03 God : Sort
【 Brother hero training in July 】 The first 04 God : greedy
【 Brother hero training in July 】 The first 05 God : Double pointer
【 Brother hero training in July 】 The first 06 God : The sliding window
【 Brother hero training in July 】 The first 07 God : Hashtable
【 Brother hero training in July 】 The first 08 God : The prefix and
【 Brother hero training in July 】 The first 09 God : Two points search
【 Brother hero training in July 】 The first 10 God : An operation
【 Brother hero training in July 】 The first 11 God : matrix
【 Brother hero training in July 】 The first 12 God : Linked list
【 Brother hero training in July 】 The first 13 God : Double linked list
【 Brother hero training in July 】 The first 14 God : Stack
【 Brother hero training in July 】 The first 15 God : Depth-first search
【 Brother hero training in July 】 The first 16 God : queue
【 Brother hero training in July 】 The first 17 God : Breadth first search
【 Brother hero training in July 】 The first 18 God : Trees
【 Brother hero training in July 】 The first 19 God : Binary tree
【 Brother hero training in July 】 The first 20 God : Search binary trees
【 Brother hero training in July 】 The first 21 God : Pile up
List of articles
- Series articles
- One 、2336. The smallest number in an infinite set
- leetcode2236 java
- Ideas
- 1. The title is infinite set , Then we construct finite sets complementary to infinite sets
- 2. Infinite sets add Elements , Then finite set remove Elements
- 3. Infinite sets remove Elements , Then finite set add Elements
- 4. Infinite set removes and returns the smallest integer in the infinite set , For a finite set, it is add Elements , And return the smallest element that is not in the finite set
- summary
One 、2336. The smallest number in an infinite set
2336. The smallest number in an infinite set
There is a set containing all positive integers [1, 2, 3, 4, 5, …] .
Realization SmallestInfiniteSet class :
SmallestInfiniteSet() initialization SmallestInfiniteSet Object to contain all Positive integer .
int popSmallest() remove And return the smallest integer in the infinite set .
void addBack(int num) If it's a positive integer num No Exist in infinite set , Then a num add to To the infinite set .
leetcode2236 java
Ideas
1. The title is infinite set , Then we construct finite sets complementary to infinite sets
2. Infinite sets add Elements , Then finite set remove Elements
3. Infinite sets remove Elements , Then finite set add Elements
4. Infinite set removes and returns the smallest integer in the infinite set , For a finite set, it is add Elements , And return the smallest element that is not in the finite set
class SmallestInfiniteSet {
HashSet<Integer> res;
public SmallestInfiniteSet() {
res = new HashSet<>();
}
public int popSmallest() {
int count = 1;
while(res.contains(count)){
count++;
}
res.add(count);
return count;
}
public void addBack(int num) {
if(res.contains(num)) res.remove(num);
}
}
summary
边栏推荐
- Double pointer (I)
- 即看即用 && 序列化和并行化 ( Serialization and Parallelism) && Pytorch官方文档总结 && 笔记 (四)
- 响应式织梦模板智能家居类网站
- CKeditor 中的粘贴不起作用(您的浏览器不支持通过工具栏或右键菜单进行粘贴,请按 Ctrl+V 进行粘贴)
- tsconfig.json文件的作用
- 路由策略-
- AcWing 1124. 骑马修栅栏 题解(欧拉回路)
- AcWing 1124. Solution to the problem of repairing fences on horseback (Euler circuit)
- AcWing 1185. 单词游戏 题解(欧拉回路)
- AcWing 1184. 欧拉回路 题解(欧拉回路)
猜你喜欢
Opencv && 把视频裁剪成指定帧率的图像集
即看即用 && 其他操作(Other Operations) && Pytorch官方文档总结 && 笔记 (八)
SYSTEMd manages redis exporter Linux
图解BERT、ELMo等 | NLP迁移学习开端
BGP-边界网关协议
Value and technical thinking of vectorization engine for HTAP
Pyinstaller打包 && 关于Enum34的问题解决 && 降低版本
LeetCode刷题--点滴记录021
(pc+wap) dream weaving template protective mask website
榜样访谈——曾钰倬:从讲座中收获经验
随机推荐
持续交付到底有什么价值?
即看即用 && Reduction Ops && Pytorch官方文档总结 && 笔记 (五)
100万人排队在等!DALL·E公开测试版,还收上费了
网络IP地址子网划分学习
What is causal deep learning? Deepmind's latest icml2022 "causality and deep learning: synergy, challenges and the future" tutorial
nodes 簡介
《Service Worker 指南-1》
图解BERT、ELMo等 | NLP迁移学习开端
软件测试工程师 | 不拼学历,还能进大厂吗?
Is it safe for flush to open Huatai Securities account?
Pyinstaller打包 && 关于Enum34的问题解决 && 降低版本
文件夹下搜索匹配文件或目录 glob()
Pytorch训练模型固定随机种子(seed),保证精度可复现
ADVANCE. AI: at present, there are few Chinese enterprises entering Latin America, which is worth exploring
即看即用 && 序列化和并行化 ( Serialization and Parallelism) && Pytorch官方文档总结 && 笔记 (四)
你为什么会做测试/开发程序员?各路伙伴描述......
Is it safe to open an account on tonghuashun online? How to buy national debt reverse repurchase
NASA「史上最强超算」投入使用,碾压老超算霸主Pleiades
Time magazine's blockbuster cover: the meta universe era will change the world
模型微调(fine-tuning)