diff --git a/NEET150/Arrays&Hashing/leetcode217.java b/NEET150/Arrays&Hashing/leetcode217.java new file mode 100644 index 0000000..f32ba8a --- /dev/null +++ b/NEET150/Arrays&Hashing/leetcode217.java @@ -0,0 +1,28 @@ + +import java.util.*; + +public class leetcode217 { + + class Solution { + + public boolean containsDuplicate(int[] nums) { + HashSet seen = new HashSet<>(); // hashset + for (int num : nums) { + if (seen.contains(num)) { + return true; + } + seen.add(num); + } + return false; + + } + } +} + +/** + * use hashset + * iterate over a for loop + * if the hashset contains the number we are trying to insert + * insert that and return true + * or else false. + */