Algorithm-determines that all characters (ASCII) are completely different (Java)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.