From 65379bc999a2d7386e2ddf2cc4c0344020b67aca Mon Sep 17 00:00:00 2001 From: priyanka-gh <72594113+priyanka-gh@users.noreply.github.com> Date: Fri, 9 Oct 2020 20:13:46 +0530 Subject: [PATCH] Added two Hashing problems --- Java/Hashing/countNonRepeatedElements.java | 15 +++++++++++++++ Java/Hashing/nonRepeatingCharacter.java | 13 +++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 Java/Hashing/countNonRepeatedElements.java create mode 100644 Java/Hashing/nonRepeatingCharacter.java diff --git a/Java/Hashing/countNonRepeatedElements.java b/Java/Hashing/countNonRepeatedElements.java new file mode 100644 index 0000000..7726a25 --- /dev/null +++ b/Java/Hashing/countNonRepeatedElements.java @@ -0,0 +1,15 @@ +static int countNonRepeated(int arr[], int n) { + Map map = new HashMap<>(); + for(int i : arr) { + if(map.get(i) != null) { + map.put(i, map.get(i) + 1); + } else { + map.put(i, 1); + } + } + int count = 0; + for(Map.Entry e : map.entrySet()) { + if(e.getValue() == 1) count++; + } + return count; +} diff --git a/Java/Hashing/nonRepeatingCharacter.java b/Java/Hashing/nonRepeatingCharacter.java new file mode 100644 index 0000000..dae4b4f --- /dev/null +++ b/Java/Hashing/nonRepeatingCharacter.java @@ -0,0 +1,13 @@ +static char nonRepeatingCharacter(String s) { + int[] a = new int[26]; + + for(int i=0;i