Skip to content

Commit

Permalink
Added codes for 26 Feb
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Feb 26, 2024
1 parent 02484ce commit ac5e2ed
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
54 changes: 54 additions & 0 deletions GeeksForGeeks/February/26-2-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//{ Driver Code Starts
//Initial Template for Java

import java.util.*;
import java.lang.*;
import java.io.*;
class GFG
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine().trim());
while(T-->0)
{
String s = br.readLine().trim();
Solution ob = new Solution();
List<String> ans = ob.AllPossibleStrings(s);
for(String i: ans)
System.out.print(i + " ");
System.out.println();

}
}
}

// } Driver Code Ends


//User function Template for Java
class Solution
{
public List<String> AllPossibleStrings(String s)
{
// Code here
int n = s.length();
ArrayList<String>res=new ArrayList<>();

for (int m = 0; m < (1 << n); m++)
{
String sb = "";
for (int i = 0; i < n; i++)
{
if ((m & (1 << i))!=0)
sb += s.charAt(i);
}

if (sb.length() > 0)
res.add(sb);
}

Collections.sort(res);
return res;
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/February/26-2-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n * 2^n)
Space complexity - O(n * 2^n)
2 changes: 2 additions & 0 deletions LeetCode/February/26-2-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(n)
25 changes: 25 additions & 0 deletions LeetCode/February/26-2-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution
{
public boolean isSameTree(TreeNode p, TreeNode q)
{
if (p == null || q == null)
return p == q;

return p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
}
}

0 comments on commit ac5e2ed

Please sign in to comment.