java - Find If Two Strings are Permutations While Prioritizing Time/Long Strings/Short Strings -
so trying find best implementation methods find if 2 strings permutations of each other 3 cases: 1. long input strings, 2. long input strings , prioritizing speed, , 3. short input strings , prioritizing space.
my implementation first case using xor:
if (string1.length() != string2.length()) { return false; } int find = 0; for(int = 0; < string1.length();i++ ){ find ^= string1.charat(i) ^ string2.charat(i); } return find == 0;
my implementation second case using hash map or hash set haven't implemented yet.
my implementation last 1 sorting strings , using java .equals compare if strings equal.
if (string1.length() != string2.length()) { return false; } char[] = string1.tochararray(); char[] b = string2.tochararray(); arrays.sort(a); arrays.sort(b); return arrays.equals(a, b);
** test input: 2 empty strings; "ab" "ba"; "abc" "acd"; "rats" "star**"; "\u263a bye now!!" "!bye now! \u263a"
would these 3 implementations best these cases?
Comments
Post a Comment