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

瑞安网站制作seo推广有哪些公司

瑞安网站制作,seo推广有哪些公司,明星网站设计论文,网站建设的销售渠道刷题刷到LeetCode回溯DFS的算法题39题的时候,碰见一个Arraylist里面的bug,其中dfs函数里面的第一个if判断里面的语句 paths.add(path); path.clear();其中path是添加了path,但是添加之后path.clear(),导致原来添加到paths的path置为空数组,因为ArrayList的add只是把一个引用指…

刷题刷到LeetCode回溯DFS的算法题39题的时候,碰见一个Arraylist里面的bug,其中dfs函数里面的第一个if判断里面的语句

paths.add(path);
path.clear();

其中path是添加了path,但是添加之后path.clear(),导致原来添加到paths的path置为空数组,因为ArrayList的add只是把一个引用指向了path,并不是深度复制,也就是说不是拷贝了一个新的ArrayList,因此改动原来的path会导致添加到paths的元素同样发生变化,直接也是clear掉了!

package org.example.SolutionTest3;import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Solution {public List<List<Integer>> combinationSum(int[] candidates, int target) {int n=candidates.length;List<Integer> path=new ArrayList<>();List<List<Integer>> paths=new ArrayList<>();return use_dfs(candidates,paths,path,target);}public List<List<Integer>> use_dfs(int[] candidates , List<List<Integer>> paths ,List<Integer> path , int target){for(int i = 0;i<candidates.length;++i){dfs(candidates,paths,path,target,target-candidates[i]);}return paths;}public void dfs(int[] candidates , List<List<Integer>> paths ,List<Integer> path , int target,int num){if(num==0&&!path.isEmpty()){System.out.println("path = " + path);paths.add(path);path.clear();//path=new ArrayList<>();return;}else if(num<0&&!path.isEmpty()){path.remove(path.size()-1);return;}for( int i = 0 ; i<candidates.length;++i){int next_num = num-candidates[i];if(next_num<0){continue;}path.add(candidates[i]);dfs(candidates,paths,path,target , next_num);}}public static void main(String[] args) {List<List<Integer>> lists = new Solution().combinationSum(new int[]{2, 3, 6, 7},7);System.out.println(lists);}
}
http://www.yidumall.com/news/20424.html

相关文章:

  • 做网站要多久seo积分系统
  • 让人做网站需要注意什么网站关键词在线优化
  • 南京在线网站制作浏览器搜索引擎大全
  • 如何修改wordpress登录页seo实战密码第三版pdf
  • 东莞做个网站盐城seo优化
  • 企业网站模板建站流程百度竞价推广登录入口
  • 常州网seo博客是什么意思
  • 网站设计 cdc网页平台做个业务推广
  • 全国水利建设监管服务平台网站2022当下社会热点话题
  • 彩页设计模板嘉兴seo外包平台
  • 做公司网站的好处以及优势网站优化助手
  • 宝塔做网站可以用什么端口常用的关键词有哪些
  • 织梦做的网站图片路径在哪里口碑营销的缺点
  • 做国外有那些网站比较好杭州优化公司哪家好
  • 去哪里找做网站 的客户seo排名诊断
  • 做网站开发需要的英语水平百家号查询排名数据查询
  • 长春做网站的seo研究协会网
  • 有多少收费网站各大网站收录入口
  • 福州网站建设网站设计网站推广湖人队最新消息
  • 网站弹窗特效seozhun
  • 南阳做网站的软文广告100字
  • 网络网站排名优化百度关键词优化方法
  • 做网站可以用别人的身份证吗百度网站名称
  • wordpress 增加小工具seo优化诊断工具
  • 政府门户网站制度建设情况网上打广告有哪些软件
  • 徐州建站平台如何推广品牌知名度
  • 青岛高端网站开发建站平台哪家好
  • 做网站页面提供的图结构网站搜索优化排名
  • 免费做自己的网站近期重大新闻事件
  • 湖北外贸网站设计制作广告公司招聘