From b76bf6a8b1b8cffb6b4cf30e7d832927cc5310a0 Mon Sep 17 00:00:00 2001 From: sumanth <58482399+sumanth00100@users.noreply.github.com> Date: Mon, 6 Apr 2026 19:14:38 -0400 Subject: [PATCH] HashSet --Design 1 --- HashSet.java | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 HashSet.java diff --git a/HashSet.java b/HashSet.java new file mode 100644 index 00000000..1d2e2fab --- /dev/null +++ b/HashSet.java @@ -0,0 +1,49 @@ +// Time Complexity : O(n) for add, remove, and contains — each linearly scans the ArrayList +// Space Complexity : O(n) — stores up to n unique keys in the ArrayList +// Did this code successfully run on Leetcode : Yes +// Any problem you faced while coding this : None + +class MyHashSet { + ArrayList hashSet = new ArrayList<>(); + + public MyHashSet() { + + } + + public void add(int key) { + boolean repeated = false; + for(int i=0;i < hashSet.size(); i++){ + if(hashSet.get(i)==key){ + repeated = true; + } + } + if(repeated== false){ + hashSet.add(key); + } + } + + public void remove(int key) { + for(int i=0;i