当前位置: 首页 > news >正文

代码随想录算法训练营第二十八天| 78 子集 90 子集|| 93 复原IP地址

78 子集

由题意可知数组中的元素互不相同,所以在dfs中我们可以将当前的path直接加入到res中。 

class Solution {List<List<Integer>>res = new ArrayList<>();List<Integer>path = new LinkedList<>();public List<List<Integer>> subsets(int[] nums) {dfs(0,nums);return res;}private void dfs(int cnt,int[] nums){res.add(new LinkedList(path));for(int i = cnt;i < nums.length;i++){path.add(nums[i]);dfs(i + 1,nums);path.remove(path.size() - 1);}}
}

时间复杂度O(n×2^{n})

空间复杂度O(n)

90 子集||

class Solution {List<List<Integer>>res = new ArrayList<>();List<Integer>path = new LinkedList<>();public List<List<Integer>> subsetsWithDup(int[] nums) {Arrays.sort(nums);dfs(0,nums);return res;}private void dfs(int cnt,int nums[]){res.add(new LinkedList(path));for(int i = cnt;i < nums.length;i++){if(i > cnt && nums[i] == nums[i - 1])continue;path.add(nums[i]);dfs(i + 1,nums);path.remove(path.size() - 1);}}
}

时间复杂度O(n×2^{n})

空间复杂度O(n)

93 复原IP地址

http://www.lryc.cn/news/236137.html

相关文章:

  • 9 HDFS架构剖析
  • Python中的迭代器、生成器和装饰器
  • 【NGINX--1】基础知识
  • 小米路由器AX1800降级后的SSH登录和关墙等命令
  • 5-什么是猴子补丁,有什么用途?什么是反射,python中如何使用反射?http和https的区别?
  • 深信服AC应用控制技术
  • 全新云开发工具箱:融合多项功能的微信小程序源码解决方案
  • Android跨进程通信,IPC,RPC,Binder系统,C语言应用层调用
  • 数据结构【DS】栈
  • 提高视频性能的 5 种方法
  • python有哪些高级的技术
  • 系列五、怎么查看默认的垃圾收集器是哪个?
  • 用向量数据库Milvus Cloud搭建GPT大模型+私有知识库的定制AI助手——PPT大纲助手
  • 浅谈基于云计算的环境智能监控系统
  • 向量机SVM代码实现
  • 基于STC12C5A60S2系列1T 8051单片的模数芯片ADC0809实现模数转换应用
  • 16. @PostConstruct注解和开关原理(验证码开关、IP开关)
  • uniapp+vue+Springboot 公司网站0~1搭建 前端前期设计篇
  • MFC 对话框
  • 关于node安装和nvm安装的问题
  • react 手机端 rc-table列隐藏(根据相关条件是否隐藏)、实现图片上传操作
  • 目标检测YOLO系列从入门到精通技术详解100篇-【目标检测】三维重建
  • H110主板搭配魔改QNCW升级小记
  • Rust8.2 Fearless Concurrency
  • 合并两个有序链表(冒泡排序实现)
  • 【iOS】——知乎日报第五周总结
  • gRPC 四模式之 双向流RPC模式
  • 五分钟,Docker安装kafka 3.5,kafka-map图形化管理工具
  • 2023.11.18html中如何使用input/button进行网页跳转
  • java文件压缩加密,使用流的方式