Skip to content

Commit

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

import java.io.*;
import java.util.*;
public class GfG
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0)
{
int n;
n = sc.nextInt();
ArrayList<String> arr = new ArrayList<String>();
for(int i = 0;i<n;i++)
{
String p = sc.next();
arr.add(p);
}
String line = sc.next();
Solution obj = new Solution();
System.out.println(obj.wordBreak(line,arr));

}
}
}
// } Driver Code Ends


//User function Template for Java

class Solution
{
public static int wordBreak(String A, ArrayList<String> B )
{
//code here
int n = A.length();
HashSet<String> wordSet = new HashSet<>(B);
boolean[] dp = new boolean[n + 1];
dp[0] = true;
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < i; j++)
{
if (dp[j] && wordSet.contains(A.substring(j, i)))
{
dp[i] = true;
break;
}
}
}
return dp[n] ? 1 : 0;
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/February/20-2-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n^2)
Space complexity - O(n)
2 changes: 2 additions & 0 deletions LeetCode/February/20-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(1)
12 changes: 12 additions & 0 deletions LeetCode/February/20-2-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution
{
public int missingNumber(int[] nums)
{
int ans = nums.length;

for (int i = 0; i < nums.length; ++i)
ans ^= i ^ nums[i];

return ans;
}
}

0 comments on commit 2e0642c

Please sign in to comment.