From d8f41439c65b6c6855e52201b686c5e20da4363a Mon Sep 17 00:00:00 2001 From: Tanmay-312 Date: Sun, 10 Mar 2024 09:37:16 +0530 Subject: [PATCH] Added codes for 10 March --- GeeksForGeeks/March/10-3-24/GFG.java | 48 +++++++++++++++++++++++++++ GeeksForGeeks/March/10-3-24/README.md | 2 ++ LeetCode/March/10-3-24/README.md | 2 ++ LeetCode/March/10-3-24/Solution.java | 22 ++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 GeeksForGeeks/March/10-3-24/GFG.java create mode 100644 GeeksForGeeks/March/10-3-24/README.md create mode 100644 LeetCode/March/10-3-24/README.md create mode 100644 LeetCode/March/10-3-24/Solution.java diff --git a/GeeksForGeeks/March/10-3-24/GFG.java b/GeeksForGeeks/March/10-3-24/GFG.java new file mode 100644 index 0000000..8929b28 --- /dev/null +++ b/GeeksForGeeks/March/10-3-24/GFG.java @@ -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 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; + } +} diff --git a/GeeksForGeeks/March/10-3-24/README.md b/GeeksForGeeks/March/10-3-24/README.md new file mode 100644 index 0000000..7384c4b --- /dev/null +++ b/GeeksForGeeks/March/10-3-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n) +Space complexity - O(n) diff --git a/LeetCode/March/10-3-24/README.md b/LeetCode/March/10-3-24/README.md new file mode 100644 index 0000000..7384c4b --- /dev/null +++ b/LeetCode/March/10-3-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n) +Space complexity - O(n) diff --git a/LeetCode/March/10-3-24/Solution.java b/LeetCode/March/10-3-24/Solution.java new file mode 100644 index 0000000..67c7cc7 --- /dev/null +++ b/LeetCode/March/10-3-24/Solution.java @@ -0,0 +1,22 @@ +class Solution +{ + public int[] intersection(int[] nums1, int[] nums2) + { + Set set = new HashSet<>(); + Set 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; + } +}