当前位置:网站首页>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 …………
边栏推荐
- 2837xd code generation - stateflow (2)
- [Yu Yue education] University Physics (Electromagnetics) reference materials of Taizhou College of science and technology, Nanjing University of Technology
- 并网逆变器PI控制(并网模式)
- Bugkuctf-web21 (detailed problem solving ideas and steps)
- Introduction et prévention des essais de pénétration
- Project practice, redis cluster technology learning (10)
- Large neural networks may be beginning to realize: the chief scientist of openai leads to controversy, and everyone quarrels
- 2837xd 代碼生成——補充(1)
- Vs+qt set application icon
- Summary of demand R & D process nodes and key outputs
猜你喜欢

Matlab生成dsp程序——官方例程学习(6)

Alibaba cloud Prometheus monitoring service

2837xd code generation - stateflow (4)

2837xd 代码生成——StateFlow(4)

Matlab generates DSP program -- official routine learning (6)

2837xd code generation - Supplement (3)

Bugkuctf-web24 (problem solving ideas and steps)

滲透測試的介紹和防範

Eslint reports an error

TD联合Modelsim进行功能仿真
随机推荐
Attack and defense world web advanced area unserialize3
Mobile mall app solution: how much is it to make an app? Detailed explanation of APP mall development content
Large neural networks may be beginning to realize: the chief scientist of openai leads to controversy, and everyone quarrels
[unreal] animation notes of the scene
Illusion -- Animation blueprint, state machine production, character walking, running and jumping action
Project practice, redis cluster technology learning (10)
Image recognition - Data Cleaning
Brief analysis of edgedb architecture
Read Day6 30 minutes before going to bed every day_ Day6_ Date_ Calendar_ LocalDate_ TimeStamp_ LocalTime
TD conducts functional simulation with Modelsim
Is the C language too fat
Vs+qt set application icon
Sil/pil test of matlab code generation
It is the most difficult to teach AI to play iron fist frame by frame. Now arcade game lovers have something
Memories of a chat
[ue5] two implementation methods of AI random roaming blueprint (role blueprint and behavior tree)
Record personal understanding and experience of game console configuration
vs+qt 设置应用程序图标
XA Transaction SQL Statements
2837xd code generation - Supplement (3)