Skip to content

Instantly share code, notes, and snippets.

@atiq-cs
Created March 24, 2019 17:25
Show Gist options
  • Save atiq-cs/975c179b36354e11aaf183d61646429c to your computer and use it in GitHub Desktop.
Save atiq-cs/975c179b36354e11aaf183d61646429c to your computer and use it in GitHub Desktop.
ref general-solving/leetcode/0078_subsets.cs
// 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