Skip to content

Commit

Permalink
Added codes for 10 March
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Mar 10, 2024
1 parent a7bac35 commit d8f4143
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
48 changes: 48 additions & 0 deletions GeeksForGeeks/March/10-3-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//{ Driver Code Starts
//Initial Template for Java



import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int tc = Integer.parseInt(br.readLine());
while (tc-- > 0) {
String str = br.readLine().trim();

String ans = new Solution().removeDuplicates(str);
System.out.println(ans);
}
}
}

// } Driver Code Ends


//User function Template for Java


class Solution
{
String removeDuplicates(String str)
{
Map<Character,Integer> exists = new HashMap<>();

String ans = "";
for(int i = 0; i < str.length(); i++)
{
if(!exists.containsKey(str.charAt(i)))
{
ans += str.charAt(i);
exists.put(str.charAt(i), 1);
}
}

return ans;
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/March/10-3-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)
2 changes: 2 additions & 0 deletions LeetCode/March/10-3-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)
22 changes: 22 additions & 0 deletions LeetCode/March/10-3-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution
{
public int[] intersection(int[] nums1, int[] nums2)
{
Set<Integer> set = new HashSet<>();
Set<Integer> intersect = new HashSet<>();
for (int i = 0; i < nums1.length; i++)
set.add(nums1[i]);

for (int i = 0; i < nums2.length; i++)
if (set.contains(nums2[i]))
intersect.add(nums2[i]);

int[] result = new int[intersect.size()];
int i = 0;

for (Integer num : intersect)
result[i++] = num;

return result;
}
}

0 comments on commit d8f4143

Please sign in to comment.