当前位置:网站首页>Remember the use of add method once
Remember the use of add method once
2022-07-02 10:07:00 【SpongeBob's nest】
I came across a relatively simple question when I was doing the question today , But the car overturned , After debugging for a long time, I didn't find the cause of the error , The output result is always empty


Suddenly I had a flash of inspiration , Could it be this add There is a problem with your method , After all, there is nothing wrong with the code logic .
So I checked the information, but I didn't get anything ……
I caught a glimpse of a search bar add Method is a copied reference or a value . I suddenly realized , Soon! ,

I left a set , The right set sets , And then run , Ha , That's true
public static void main(String[] args) {
ArrayList<Integer>list = new ArrayList<>();
ArrayList<ArrayList<Integer>>result = new ArrayList<>();
result.add(list);
for(int i = 0; i < 5; i++){
list.add(i);
System.out.println(" Results to be selected "+list);
System.out.println(" Result set :"+result);
System.out.println("========================");
}
}
We can clearly see that we put list Has been added to result in , however list After adding elements in ,result The elements in have also changed , This explanation add What's coming in is list References to , It's not worth it .
public static void main(String[] args) {
ArrayList<Integer>list = new ArrayList<>();
ArrayList<ArrayList<Integer>>result = new ArrayList<>();
result.add(list);
for(int i = 0; i < 5; i++){
list.add(i);
System.out.println(" Results to be selected "+list);
System.out.println(" Result set :"+result);
list.remove(list.size()-1);
System.out.println("result change "+result);
System.out.println("========================");
}
}
So , After going through a lot of hardships, the ninety-nine and eighty-one difficulties , I finally solved this problem

Attach a link to the original title : Find the path where the sum of binary tree values is a specific value
Simple backtracking algorithm .
error (×):

correct (√):

Okay , This mistake will serve as a lesson …………
边栏推荐
- Is the C language too fat
- [unreal] animation notes of the scene
- 2837xd code generation - Supplement (3)
- Image recognition - Data Acquisition
- How to handle error logic gracefully
- 高考那些事
- What is the relationship between realizing page watermarking and mutationobserver?
- Centos7 one click compilation and installation of PHP script
- 2837xd代码生成模块学习(4)——idle_task、Simulink Coder
- Blender多镜头(多机位)切换
猜你喜欢

阿里云Prometheus监控服务

UE4 night lighting notes
![[unreal] key to open the door blueprint notes](/img/28/f2b00d84dc05183ce93e2a8ee3555f.png)
[unreal] key to open the door blueprint notes
![[ue5] two implementation methods of AI random roaming blueprint (role blueprint and behavior tree)](/img/dd/cbe608fcbbbdf187dd6f7312271d2e.png)
[ue5] two implementation methods of AI random roaming blueprint (role blueprint and behavior tree)

Eslint reports an error
![[illusory] weapon slot: pick up weapons](/img/a7/1e395fc9cdfd0359e7ae4d2313290d.png)
[illusory] weapon slot: pick up weapons

2837xd code generation - Summary

Bookmark collection management software suspension reading and data migration between knowledge base and browser bookmarks

Read 30 minutes before going to bed every day_ day4_ Files

ue虛幻引擎程序化植物生成器設置——如何快速生成大片森林
随机推荐
MySQL index
Project practice, redis cluster technology learning (12)
阿里云Prometheus监控服务
PI control of grid connected inverter (grid connected mode)
Configuration programmée du générateur de plantes du moteur illusoire UE - - Comment générer rapidement une grande forêt
Summary of demand R & D process nodes and key outputs
Attack and defense world web advanced area unserialize3
职业规划和发展
JDBC review
Image recognition - Data Cleaning
Read Day6 30 minutes before going to bed every day_ Day6_ Date_ Calendar_ LocalDate_ TimeStamp_ LocalTime
Binary and decimal system of C language
三相并网逆变器PI控制——离网模式
vs+qt 设置应用程序图标
TD conducts functional simulation with Modelsim
2837xd 代碼生成——StateFlow(4)
Junit4运行mvn test 测试套件升级方案
2837xd code generation module learning (2) -- ADC, epwm module, timer0
Illusion -- Animation blueprint, state machine production, character walking, running and jumping action
In SQL injection, why must the ID of union joint query be equal to 0