* * Implement an algorithm that determines whether all characters of a string are all different. Here we require that additional storage structures not be allowed to be used.
Given a string inistring, return a bool value, true to mean that all characters are different, and false to represent the same characters. Guarantees that the characters in the string are ASCII characters. The length of the string is less than or equal to 3000.
Test Sample:
"Aeiou"
Return: True
"BarackObama"
Back: false**
Package question1_1;
public class Question {public static Boolean isuniquechars (String str) {if (Str.length () > 128) {
return false;
int checker = 0;
for (int i = 0; i < str.length (); i++) {int val = Str.charat (i)-' a ';
if ((Checker & (1 << val)) > 0) return false;
Checker |= (1 << val);
return true;
public static Boolean isUniqueChars2 (String str) {if (Str.length () > 128) {return false;
} boolean[] Char_set = new boolean[128];
for (int i = 0; i < str.length (); i++) {int val = Str.charat (i);
if (Char_set[val]) return false;
Char_set[val] = true;
return true;
public static void Main (string[] args) {string[] words = {"ABCDE", "Hello", "apple", "Kite", "Padle"}; for (String word:words) {System.out.println (Word + ":" + isuniquechars (Word) + "" + isUniqueChars2 (word));
}
}
}