Question: hello, does the following code run on O(n)? if so, can you please explain in detail how it does? and if not, could you write
Presentation 1 jave X *Presentation 2.java 1 import java.util.Arrays; 2 3 public class Presentationi public static void main(String[] args) { permutation("Charles", "ArchLes"); // true permutation("df", "TY"); // false permutation("asdf", "fdsg"); // false permutation("JOHN", "OHNj"); // true permutation("Wow", "wow"); // false 5 60 7 8 9 10 11 12 13 14 15 16 17e 18 19 2e 21 22 23 24 25 26 27 28 29 BO public static boolean permutation(String si, String s2) // Check the length of both strings int lengthi = $1. length(); int length2 = 52. length(); if (length1 != length2) return false; B6 1/ Change the two strings in lower case letters s1 - 51.toLowerCase(); 52 - 52.toLowerCase(); 1/ Create two arrays of characters charll array1 - 51. toCharArray(); char il array2 = 52.toCharArray(); 11 Sort both arrays Arrays. sort(arrayi); Arrays.sort(array2) return Arrays.equals(array, array2)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
