Java lookup string1 and string2 are not the same letter type and number (string1 is string2 re-composition)

Source: Internet
Author: User

ImportJava.util.*; Public classSame { Public BooleanChecksam (String Stringa, String stringb) {//Write code here        int[] str1=New int[256]; int[] str2=New int[256]; if(Stringa.length ()! =stringb.length ()) {            return false; }         for(intI=0;i<stringa.length (); i++) {Str1[stringa.charat (i)]++; Str2[stringb.charat (i)]++; }         for(intj=0;j<256;j++){            if(str1[j]!=Str2[j]) {                return false; }        }        return true; }}

Note the points:

1. You can use ToCharArray () and Str.charat (i) two ways to get each bit of the string

The 2.char type can be automatically converted to the int type. Converts the char type to the ASCII code corresponding to the character

3.int[] str1=new int[256] global variable no initial value defaults to 0, if int[] str; The default value is null. Global variable integer default value is also 0; local variables are not initialized automatically

4. Drawer algorithm, n+1 a ball into n drawers inside, at least one drawer inside more than 1 balls. In the same way, all ASCII characters are 256 and stored in a hash table.

Java lookup string1 and string2 are not the same letter type and number (string1 is string2 re-composition)

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.