Solution 1: accepted 2ms
- Need to reset the condition of ArrayList using
temp.remove(temp.size() - 1). - Why
result.add(new ArrayList<Integer>(temp))? It passes a reference rather than an object. So if we useresult.add(temp), we will get the same temp multiple times. In addition, temp will contains no elements at the end of the recursion, so we will always get a list of[]at the end.
|
|
Alternative
|
|