determine that all characters are Embox (Java)
This address: Http://blog.csdn.net/caroline_wendy
ASCII code altogether 256 bits, the character difference judgment , uses the bit operation to solve (11 rows), the bit operation can also sort the non-repeating number array (11 lines).
A bit is a two-valued storage unit that operates directly to determine repetitive and non-repeating sorts, saves time and space, and can use a bool array instead of its function.
Code:
/** * Created by C.l.wang */public class Main {public static void main (string[] args) {String str = "God+byte" ; System.out.println ("is unique:" + isuniquechars (str)); Int[] arr = {4, 5, 1, 6, 3, 2}; Sort (arr); System.out.print ("sorted array:"); for (int i:arr) {System.out.print (i + ""); }}/** * Determines whether characters in a string are unique * * @param str String * @return is unique */public static Boolean Isuniquech ARS (String str) {if (Str.length () >) return false; Boolean[] bs = new boolean[256]; for (int i = 0; i < str.length (); ++i) {int val = Str.charat (i); if (Bs[val]) return false; Bs[val] = true; } return true; }/** * bit sort (no repeating array) * * @param arr to sort array */public static void sort (int[] arr) {Final int MAX = 256; Boolean[] bs = new Boolean[max]; for (int i:arr) bs[i] = true;int n = 0; for (int i = 0; i < MAX; ++i) {if (Bs[i]) arr[n++] = i; } }}
Output:
Algorithm-determines that all characters (ASCII) are completely different (Java)