Lintcode-compare Strings

Source: Internet
Author: User

Compare strings A and B, determine whether a contains all of the characters in B.

The characters in string A and B is all Upper case letters.

Example

For A = "ABCD", B = "ABC", return true.

For A = "ABCD" B = "AABC", return false.

Solution:

1  Public classSolution {2     /**3      * @parama:a string includes Upper case letters4      * @paramb:a string includes Upper case letter5      * @return: If string A contains all of the characters in B return true else return false6      */7      Public Booleancomparestrings (String A, String B) {8         int[] record =New int[256];9Arrays.fill (record,0);Ten          for(intI=0;i<a.length (); i++){ One             intIND = (int) A.charat (i); Arecord[ind]++; -         } -  the          for(intI=0;i<b.length (); i++){ -             intIND = (int) B.charat (i); -             if(record[ind]==0)return false; -             Elserecord[ind]--; +         } -  +         return true; A     } at}

Lintcode-compare Strings

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.