Reverse String LeetCode JAVA 2 Different Solutions
public static void main(String arg[]){ Scanner sc=new Scanner(System.in); System.out.println("Enter total number of characters in string"); int n=sc.nextInt(); char arr[]=new char[n]; for(int i=0;i<n;i++){ arr[i]=sc.next().charAt(0); ; } for(int i=0;i<n;i++){ System.out.print(arr[i]+" "); } /* Approach 1 : Swapping elements till half. Leetcode stats: Runtime 112 seconds, Memory 42.4 MB. int start=0; int end=arr.length-1; while(start<end){ char temp; temp=arr[start]; arr[start]=arr[end]; arr[end]=temp; start++; end--; } for(int i=0;i<n;i++){ System.out.print(arr[i]+" "); } */ //============================================================ /* Approach 2 : Using the StringBuffer reverse method. Leetcode stats: Runtime 114 seconds, Memory 41.8 MB. String str = new String(arr); StringBuffer sb=new StringBu...