Created
March 24, 2019 17:25
-
-
Save atiq-cs/975c179b36354e11aaf183d61646429c to your computer and use it in GitHub Desktop.
ref general-solving/leetcode/0078_subsets.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for leetcode meetup | |
// O(2^n), O(2^n) | |
public IList<IList<int>> Subsets(int[] nums, int index = nums.Length) { | |
if (index == 0) | |
return new List<IList<int>>(new IList<int>[] { new List<int>() }); | |
var temp = Subsets(nums, index - 1); | |
int tempLength = temp.Count; | |
for (int i = 0; i < tempLength; i++) { | |
temp.Add(new List<int>(temp[i])); | |
temp[temp.Count - 1].Add(nums[index - 1]); | |
} | |
return temp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment