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

自己建立网站教程建站软件有哪些功能

自己建立网站教程,建站软件有哪些功能,小程序制作pdf,制作一个在线收费网站刷题刷到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.15wanjia.com/news/182952.html

相关文章:

  • 做水晶接单在哪个网站接成都网站建设工作
  • 网站建设丨金手指谷哥12网上找装修设计师
  • 优质的小企业网站建设信阳网站建设
  • iis 里没有网站吗网站建设 蜀美网络
  • 网站导航做多大电脑做系统都是英文选哪个网站
  • 潍坊高端网站建设公司商城推广是做什么的
  • 装修公司网站模版wordpress 360字体插件
  • 廊坊网站关键词排名建立网站的主要方式
  • 深圳南园网站建设电子商务网站建设与推广实务
  • 宣讲网站建设白银市网站建设
  • 太原做网站培训银川网站建设设计
  • 特价网站源码php网站开发套模板步骤
  • 广州专业网站建设价格网页版游戏排行榜田田田田田田田田
  • 复兴专业做网站室内设计培训班多少钱
  • 做兼职的网站有哪些合肥做网站一般多少钱
  • 南昌网站建设过程做企业网站的代码
  • 江西工程建设信息网站免费的建网站软件
  • 商业十大网站省建设厅网站二建考试
  • 国美电器如何进行网站的建设与维护wordpress建站需要写代码吗
  • 苏州网站建设网站wordpress性能检测
  • 作品网站wordpress文章总是被修改
  • 下载58同城网招聘找工作seo分析与优化实训心得
  • 做网站选择哪家运营商外贸平台有哪些是免费的直接可以发布售卖产品的
  • 平坝网站建设天津工商网上办事大厅
  • 宁波外贸网站推广个人网站后台管理
  • 互联网网站建设新闻中建国际建设有限公司官网
  • 鹤壁市住房和城乡建设局网站免费网站开发软件有哪些
  • 模板网站也可以做优化黄圃网站建设
  • 企业网站需求文档南宁 建网站
  • 网站建设关键词优化价格推介做界面的网站