码迷,mamicode.com
首页 > 其他好文 > 详细

[lintcode easy]Compare Strings

时间:2015-12-03 07:11:20      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

Compare Strings

 

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

The characters in string A and B are all Upper Case letters.

Example

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

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

Note

The characters of B in A are not necessary continuous or ordered.

 

public class Solution {
    /**
     * @param A : A string includes Upper Case letters
     * @param B : A string includes Upper Case letter
     * @return :  if string A contains all of the characters in B return true else return false
     */
    public boolean compareStrings(String A, String B) {
        // write your code here
        
        int m=A.length();
        int n=B.length();
        if(n>m) return false;
        boolean[] isCount=new boolean[m];
        int count=0;
        
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(B.charAt(i)==A.charAt(j) && isCount[j]==false)
                {
                    count++;
                    isCount[j]=true;
                    break;
                }
          }
        }
        
        if(count==n) return true;
        else return false;
    }
}

 

[lintcode easy]Compare Strings

标签:

原文地址:http://www.cnblogs.com/kittyamin/p/5014956.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!