diff --git a/PalindromPartitioning.cs b/PalindromPartitioning.cs new file mode 100644 index 00000000..97ea6999 --- /dev/null +++ b/PalindromPartitioning.cs @@ -0,0 +1,43 @@ +public class Solution { + public IList> Partition(string s) { + List> result = new (); + helper(s,0,new List(),result); + return result; + } + + public void helper(string s,int pivot,List path, List> result) + { + if(s.Length==pivot) + { + result.Add(new List(path)); + return; + } + for(int i=pivot;i For n length string, exponential partitions × (palindrome checks + creating substrings) + +// Space Complexity: +// O(n^2) (substring creation and recursion stack) \ No newline at end of file diff --git a/Subsets.cs b/Subsets.cs new file mode 100644 index 00000000..fbc6e63f --- /dev/null +++ b/Subsets.cs @@ -0,0 +1,21 @@ +public class Solution +{ + public IList> Subsets(int[] nums) + { + List> result = new(); + result.Add(new List()); + for (int i = 0; i < nums.Length; i++) + { + int size = result.Count; + for (int j = 0; j < size; j++) + { + List subset = new List(result[j]); + subset.Add(nums[i]); + result.Add(subset); + } + } + + return result; + } +} +//Time and space - O(n * 2^n)