[lintcode easy]Compare Strings

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;
    }
}
时间: 2024-10-24 22:36:39

[lintcode easy]Compare Strings的相关文章

lintcode 容易题:Compare Strings 比较字符串

题目: 比较字符串 比较两个字符串A和B,确定A中是否包含B中所有的字符.字符串A和B中的字符都是 大写字母 样例 给出 A = "ABCD" B = "ACD",返回 true 给出 A = "ABCD" B = "AABC", 返回 false 注意 在 A 中出现的 B 字符串里的字符不需要连续或者有序. 解题: 用数组,或者用HashMap都可以,由于char String转换成Integer不是很熟悉,搞了好久...

LintCode: Compare Strings

C++ 1 class Solution { 2 public: 3 /** 4 * @param A: A string includes Upper Case letters 5 * @param B: A string includes Upper Case letter 6 * @return: if string A contains all of the characters in B return true 7 * else return false 8 */ 9 bool com

Lintcode55 Compare Strings solution 题解

[题目描述] 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. Notice:The characters of B in A are not necessary continuous or ordered. 比较两个字符串A和B,确定A中是否包含B中所有的

[Lintcode easy]Longest Words

Longest Words Given a dictionary, find all of the longest words in the dictionary. Example Given { "dog", "google", "facebook", "internationalization", "blabla" } the longest words are(is) ["internati

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. Notice The characters of B in A are not necessary continuous or ordered. Example For A = "ABCD", B

[lintcode easy]Merge Sorted Array

Merge Sorted Array Given two sorted integer arrays A and B, merge B into A as one sorted array. Have you met this question in a real interview? Yes Which company asked you this question? Airbnb Alibaba Amazon Apple Baidu Bloomberg Cisco Dropbox Ebay

[lintcode easy]Reverse Integer

Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-bit integer). Example Given x = 123, return 321 Given x = -123, return -321 \\\The length of Int data is from -2^31 to 2^31-1; [-2^31 , 2^31 -1] 即 [-2147483648,214

[lintcode easy]Add Binary

Add Binary Given two binary strings, return their sum (also a binary string).   Example a = 11 b = 1 Return 100 solution: 比较两个string的长度,将长读较小的string左边用0补齐. 设置进位标志flag.循环结束后如果进位标识大于0,则返回进位加上其他string:否则返回新string: char 0对应ASCII码表中30 1对应31....减去0所对应的值以后就

LeetCode.1170-比较字符串中最小字符的出现频率(Compare Strings by Frequency of the Smallest Char)

这是小川的第412次更新,第444篇原创 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第263题(顺位题号是1170).在一个非空字符串s上定义一个函数f(s),该函数计算s中最小字符的出现频率.例如,如果s ="dcce",则f(s)= 2,因为最小字符为"c",其频率为2. 现在,给定字符串数组queries和words,返回一个整数数组answer, 其中每个answer[i]是使得f(queries[i]) < f(W)的单词数量,其