1662. 检查两个字符串数组是否相等

1662. 检查两个字符串数组是否相等

string水题

一、用+

class Solution {
public:
    bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {
        int lenA=word1.size();
        int lenB=word2.size();

        string A,B;
        for(string temp: word1)
        {
            A+=temp;
        }

        for(string temp: word2)
        {
            B+=temp;
        }

        if( A==B )
        {
            return true;
        }
        else
        {
            return false;
        }
    }
};

二、用append运行速度更快

class Solution {
public:
    bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {
        int lenA=word1.size();
        int lenB=word2.size();

        string A,B;
        for(string temp: word1)
        {
            //用的地方
            A.append(temp);
        }

        for(string temp: word2)
        {
            B.append(temp);
        }

        if( A==B )
        {
            return true;
        }
        else
        {
            return false;
        }
    }
};
全部评论

相关推荐

最喜欢秋天的火龙果很...:第一份工作一定要往大的去,工资低点没事。后面换工作会更好找,即使你去小公司,你也不可能不会换工作的。所以找大的去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务