题解 | #确定两串乱序同构#

确定两串乱序同构

https://www.nowcoder.com/practice/164929d4acd04de5b0ee2d93047b3b20

class Same {
  public:
    bool checkSam(string stringA, string stringB) {
        // write code here
        array<int, 128> bufA{ 0 };  // 保存字符串a的遍历值
        array<int, 128> bufB{ 0 };  // 保存字符串b的遍历值
        for (auto& ch : stringA) {
            bufA[ch] += 1;
        }
        for (auto& ch : stringB) {
            bufB[ch] += 1;
        }
        for (int i = 0; i < 128; i++) {
            if (bufA[i] != bufB[i]) {
                return false;
            }
        }
        return true;
    }
};

使用两个数组来保存每个字符串遍历后的值,最后比对两个字符串的值

#我的实习求职记录#
程序员面试宝典题解 文章被收录于专栏

程序员面试宝典题解

全部评论

相关推荐

点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务