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;
        }
    }
};
全部评论

相关推荐

牛客44320985...:你的当务之急是把这个糖的要死的沟槽ide主题改了
点赞 评论 收藏
分享
03-10 11:23
门头沟学院 Java
鹿LF:计算机面试就跟数学题一样,没什么实际价值,但只能这么筛选,本质是考察你的努力,智力和学习能力
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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