Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ae02ec2

Browse files
committed
Time: 1 ms (98.83%), Space: 37.7 MB (76.02%) - LeetHub
1 parent 1757659 commit ae02ec2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

0078-subsets/0078-subsets.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.LinkedList
2+
3+
class Solution {
4+
private fun subsetsMutable(
5+
nums: IntArray,
6+
i: Int,
7+
now: LinkedList<Int>,
8+
result: MutableList<List<Int>>,
9+
) {
10+
if (i == nums.size) {
11+
@Suppress("UNCHECKED_CAST")
12+
result += now.clone() as List<Int>
13+
return
14+
}
15+
16+
subsetsMutable(nums, i + 1, now, result)
17+
now += nums[i]
18+
subsetsMutable(nums, i + 1, now, result)
19+
now.removeLast()
20+
}
21+
22+
fun subsets(nums: IntArray): List<List<Int>> {
23+
val result = mutableListOf<List<Int>>()
24+
subsetsMutable(nums, 0, LinkedList(), result)
25+
26+
return result
27+
}
28+
}

0 commit comments

Comments
 (0)