Friday, March 10, 2023

Reverse a string in Java without using any inbuilt function

 Reverse a string in Java without using any inbuilt function 

  1. Time Complexity : O(n)
  2. Space Complexity : O(n)

public static String reverseWord(String str)
    {
        // Reverse the string str
        
        int n = str.length();
        String temp="" ;
        
        for(int i=n-1;i>=0;i--){
            
            temp+=str.charAt(i);
            
        }
        
        return temp;
    }

Coding India


No comments:

Post a Comment

Quick Sort in Java

 Quick Sort in Java Time complexity : O(n*n) - Worst case , O(nlogn) - Best Case Space complexity : O(logn) - height of recursion tree Best ...