From 98815924e3da79548d82f50e5e4b8ae306dd546a Mon Sep 17 00:00:00 2001 From: saranshkotnala <66181092+saranshkotnala@users.noreply.github.com> Date: Mon, 4 Oct 2021 00:35:05 +0530 Subject: [PATCH 1/4] Create reverse.java --- array/reverse an array/java/reverse.java | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 array/reverse an array/java/reverse.java diff --git a/array/reverse an array/java/reverse.java b/array/reverse an array/java/reverse.java new file mode 100644 index 0000000..cd35feb --- /dev/null +++ b/array/reverse an array/java/reverse.java @@ -0,0 +1,41 @@ +import java.io.*; +import java.util.*; + +public class Main{ + public static void display(int[] a){ + StringBuilder sb = new StringBuilder(); + + for(int val: a){ + sb.append(val + " "); + } + System.out.println(sb); + } + + public static void reverse(int[] a){ + int li = 0; + int ri = a.length - 1; + + while(li < ri){ + int temp = a[li]; + a[li]= a[ri]; + a[ri] = temp; + + li++; + ri--; + } + } + +public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int n = Integer.parseInt(br.readLine()); + int[] a = new int[n]; + for(int i = 0; i < n; i++){ + a[i] = Integer.parseInt(br.readLine()); + } + + reverse(a); + display(a); + } + +} From e7f91390bda247e49f91ca113ab4e0ce438e1042 Mon Sep 17 00:00:00 2001 From: saranshkotnala <66181092+saranshkotnala@users.noreply.github.com> Date: Mon, 4 Oct 2021 00:46:58 +0530 Subject: [PATCH 2/4] Delete reverse.java --- array/reverse an array/java/reverse.java | 41 ------------------------ 1 file changed, 41 deletions(-) delete mode 100644 array/reverse an array/java/reverse.java diff --git a/array/reverse an array/java/reverse.java b/array/reverse an array/java/reverse.java deleted file mode 100644 index cd35feb..0000000 --- a/array/reverse an array/java/reverse.java +++ /dev/null @@ -1,41 +0,0 @@ -import java.io.*; -import java.util.*; - -public class Main{ - public static void display(int[] a){ - StringBuilder sb = new StringBuilder(); - - for(int val: a){ - sb.append(val + " "); - } - System.out.println(sb); - } - - public static void reverse(int[] a){ - int li = 0; - int ri = a.length - 1; - - while(li < ri){ - int temp = a[li]; - a[li]= a[ri]; - a[ri] = temp; - - li++; - ri--; - } - } - -public static void main(String[] args) throws Exception { - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - - int n = Integer.parseInt(br.readLine()); - int[] a = new int[n]; - for(int i = 0; i < n; i++){ - a[i] = Integer.parseInt(br.readLine()); - } - - reverse(a); - display(a); - } - -} From f597d87c5bf7d4e0f5d06590f99b9f2afe1d1872 Mon Sep 17 00:00:00 2001 From: saranshkotnala <66181092+saranshkotnala@users.noreply.github.com> Date: Mon, 4 Oct 2021 01:01:39 +0530 Subject: [PATCH 3/4] Added reverse an array java solution * takes an array as input and prints its reverse in java * Takes O(N) time * Takes O(1) space --- array/reverse an array/java/reverse.java | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 array/reverse an array/java/reverse.java diff --git a/array/reverse an array/java/reverse.java b/array/reverse an array/java/reverse.java new file mode 100644 index 0000000..cd35feb --- /dev/null +++ b/array/reverse an array/java/reverse.java @@ -0,0 +1,41 @@ +import java.io.*; +import java.util.*; + +public class Main{ + public static void display(int[] a){ + StringBuilder sb = new StringBuilder(); + + for(int val: a){ + sb.append(val + " "); + } + System.out.println(sb); + } + + public static void reverse(int[] a){ + int li = 0; + int ri = a.length - 1; + + while(li < ri){ + int temp = a[li]; + a[li]= a[ri]; + a[ri] = temp; + + li++; + ri--; + } + } + +public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int n = Integer.parseInt(br.readLine()); + int[] a = new int[n]; + for(int i = 0; i < n; i++){ + a[i] = Integer.parseInt(br.readLine()); + } + + reverse(a); + display(a); + } + +} From c69cf5ab697d1a2383c7ef290b4d5cb1f08bcd3e Mon Sep 17 00:00:00 2001 From: saranshkotnala <66181092+saranshkotnala@users.noreply.github.com> Date: Mon, 4 Oct 2021 01:04:53 +0530 Subject: [PATCH 4/4] Update Contributors.md added name to contributors.md --- Contributors.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Contributors.md b/Contributors.md index cfc8c54..f437156 100644 --- a/Contributors.md +++ b/Contributors.md @@ -22,3 +22,4 @@ Welcome to the list of people who contributed to this repo 💥 5. [iamprofessor1](https://github.com/iamprofessor1)(Added Kth largest leetcode in cpp) 6. [dcod3r](https://github.com/dcod3r) 7. [Ayansh](https://github.com/badasschef) +8. [Saransh](https://github.com/saranshkotnala)