lintcode 比较字符串

作者: yzawyx0220 | 来源:发表于2017-01-03 10:58 被阅读44次

比较两个字符串A和B,确定A中是否包含B中所有的字符。字符串A和B中的字符都是 大写字母
样例
给出 A = "ABCD" B = "ACD",返回 true
给出 A = "ABCD" B = "AABC", 返回 false
比较简单的题,直接上代码

class Solution {
public:
    /**
     * @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
     */
    bool compareStrings(string A, string B) {
        // write your code here
        sort(A.begin(),A.end());
        sort(B.begin(),B.end());
        int i = 0,j = 0;
        while (i < A.size() && j < B.size()) {
            if (A[i] != B[j]) i++;
            else {
                i++;
                j++;
            }
        }
        return (i == A.size() && j != B.size()) ? false : true;
    }
};

相关文章

  • lintcode 比较字符串

    比较两个字符串A和B,确定A中是否包含B中所有的字符。字符串A和B中的字符都是 大写字母样例给出 A = "ABC...

  • OJ lintcode 比较字符串

    比较两个字符串A和B,确定A中是否包含B中所有的字符。字符串A和B中的字符都是 大写字母注意事项在 A 中出现的 ...

  • [leetcode/lintcode 题解] 解码字符串 ·

    leetcode/lintcode 题解] 解码字符串 · Decode String 【题目描述】 给出一个表...

  • 字符串比较-面试题

    这是近几天在LintCode上遇到的一道题,题目如下: 比较两个字符串A和B,确定A中是否包含B中所有的字符。字符...

  • python 字符串倒置(lintcode)

    描述: 字符串置换 原题地址:http://www.lintcode.com/zh-cn/problem/stri...

  • lintCode题解(8)

    标签(空格分隔): lintCode 旋转字符串 给定一个字符串和一个偏移量,根据偏移量旋转字符串(从左向右旋转)...

  • Delete Digits

    Delete Digits 今天是一道有关字符串和贪婪算法的题目,来自LintCode,难度为Medium,Acc...

  • lintcode 字符串查找

    对于一个给定的 source 字符串和一个 target 字符串,你应该在 source 字符串中找出 targe...

  • lintcode 旋转字符串

    给定一个字符串和一个偏移量,根据偏移量旋转字符串(从左向右旋转)题目比较简单,只要注意处理一下旋转的个数大于字符串...

  • LintCode交叉字符串

    给出三个字符串:s1、s2、s3,判断s3是否由s1和s2交叉构成。 样例比如 s1 = "aabcc" s2 =...

网友评论

    本文标题:lintcode 比较字符串

    本文链接:https://www.haomeiwen.com/subject/pgwgvttx.html