diff --git a/palindrome_partionining.java b/palindrome_partionining.java new file mode 100644 index 00000000..736687a9 --- /dev/null +++ b/palindrome_partionining.java @@ -0,0 +1,32 @@ + +class Solution { + List> result; + public List> partition(String s) { + this.result= new ArrayList<>(); + helper(s,0,new ArrayList<>()); + return result; + } + private void helper(String s,int pivot,List path){ + if(pivot == s.length()){ + result.add(new ArrayList<>(path)); + return; + } + + for(int i=pivot; i> result; +// public List> subsets(int[] nums) { +// this.result = new ArrayList<>(); +// List path = new ArrayList<>(); +// helper(nums, 0, path); +// return result; +// } +// private void helper(int[] nums, int i,List path){ +// //base +// if(i==nums.length) +// { +// result.add(new ArrayList<>(path)); +// return; +// } +// //logic +// //0 +// helper(nums,i+1,path); +// path.add(nums[i]); +// helper(nums,i+1,path); +// path.remove(path.size()-1); +// } +// } + +//Time Complexity: O(n × 2ⁿ) +//Space Complexity: O(n) +class Solution { + List> result; + public List> subsets(int[] nums) { + this.result = new ArrayList<>(); + List path = new ArrayList<>(); + helper(nums,path,0); + return result; + } + private void helper(int[] nums,List path,int pivot){ + result.add(new ArrayList(path)); + for(int i=pivot;i