From 9e2d34b5910726216eb0be53276258308e635c2b Mon Sep 17 00:00:00 2001 From: abhikbob Date: Mon, 7 Oct 2019 12:37:33 +0530 Subject: [PATCH 1/2] Added firstDuplicate, firstNotRepeatingCharacter and rotateImage --- src/com/codesignal/firstDuplicate.java | 10 ++++++++++ src/com/codesignal/firstNotRepeatingCharacter.java | 12 ++++++++++++ src/com/codesignal/rotateImage.java | 11 +++++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/com/codesignal/firstDuplicate.java create mode 100644 src/com/codesignal/firstNotRepeatingCharacter.java create mode 100644 src/com/codesignal/rotateImage.java diff --git a/src/com/codesignal/firstDuplicate.java b/src/com/codesignal/firstDuplicate.java new file mode 100644 index 00000000..96289440 --- /dev/null +++ b/src/com/codesignal/firstDuplicate.java @@ -0,0 +1,10 @@ +int firstDuplicate(int[] a) { + HashSet hs = new HashSet(); + for(int i:a){ + if(!hs.contains(i))hs.add(i); + else return i; + } + +return -1; +} + diff --git a/src/com/codesignal/firstNotRepeatingCharacter.java b/src/com/codesignal/firstNotRepeatingCharacter.java new file mode 100644 index 00000000..07cde826 --- /dev/null +++ b/src/com/codesignal/firstNotRepeatingCharacter.java @@ -0,0 +1,12 @@ +char firstNotRepeatingCharacter(String s) { + + for(int i=0; i=0;j--){ + ans[i][l-j-1] = a[j][i];} + +return ans;} + From 237eba7189cab0ff9ee176cf3e99110b25a5489e Mon Sep 17 00:00:00 2001 From: abhikbob Date: Mon, 7 Oct 2019 18:15:36 +0530 Subject: [PATCH 2/2] Made codes into working programs --- src/com/codesignal/FirstDuplicate.java | 21 ++++++++++++++ .../FirstNotRepeatingCharacter.java | 24 +++++++++++++++ src/com/codesignal/RotateImage.java | 29 +++++++++++++++++++ src/com/codesignal/firstDuplicate.java | 10 ------- .../firstNotRepeatingCharacter.java | 12 -------- src/com/codesignal/rotateImage.java | 11 ------- 6 files changed, 74 insertions(+), 33 deletions(-) create mode 100644 src/com/codesignal/FirstDuplicate.java create mode 100644 src/com/codesignal/FirstNotRepeatingCharacter.java create mode 100644 src/com/codesignal/RotateImage.java delete mode 100644 src/com/codesignal/firstDuplicate.java delete mode 100644 src/com/codesignal/firstNotRepeatingCharacter.java delete mode 100644 src/com/codesignal/rotateImage.java diff --git a/src/com/codesignal/FirstDuplicate.java b/src/com/codesignal/FirstDuplicate.java new file mode 100644 index 00000000..b9429e61 --- /dev/null +++ b/src/com/codesignal/FirstDuplicate.java @@ -0,0 +1,21 @@ +import java.util.*; + +public class sol{ + +static int FirstDuplicate(int[] a) { + HashSet hs = new HashSet(); + for(int i:a){ + if(!hs.contains(i))hs.add(i); + else return i; + } + +return -1; +} + +public static void main(String args[]){ + int[] a={2, 1, 3, 5, 3, 2}; + System.out.print("First duplicate: "+FirstDuplicate(a)); + +} + +} diff --git a/src/com/codesignal/FirstNotRepeatingCharacter.java b/src/com/codesignal/FirstNotRepeatingCharacter.java new file mode 100644 index 00000000..e204bd9f --- /dev/null +++ b/src/com/codesignal/FirstNotRepeatingCharacter.java @@ -0,0 +1,24 @@ +import java.util.*; + +public class sol{ + +static char FirstNotRepeatingCharacter(String s) { + + for(int i=0; i=0;j--){ + ans[i][l-j-1] = a[j][i];} + +return ans;} + + + +public static void main(String args[]){ + int[][] a= {{1,2,3},{4,5,6},{7,8,9}}; + int[][] ans=RotateImage(a); + for(int i=0;i hs = new HashSet(); - for(int i:a){ - if(!hs.contains(i))hs.add(i); - else return i; - } - -return -1; -} - diff --git a/src/com/codesignal/firstNotRepeatingCharacter.java b/src/com/codesignal/firstNotRepeatingCharacter.java deleted file mode 100644 index 07cde826..00000000 --- a/src/com/codesignal/firstNotRepeatingCharacter.java +++ /dev/null @@ -1,12 +0,0 @@ -char firstNotRepeatingCharacter(String s) { - - for(int i=0; i=0;j--){ - ans[i][l-j-1] = a[j][i];} - -return ans;} -