Leetcode—734. 句子相似性【简单】Plus

2025每日刷题(210)

Leetcode---734. 句子相似性

实现代码

cpp 复制代码
class Solution {
public:
    bool areSentencesSimilar(vector<string>& sentence1, vector<string>& sentence2, vector<vector<string>>& similarPairs) {
        if(sentence1.size() != sentence2.size()) {
            return false;
        }

        unordered_map<string, unordered_set<string>> map;
        for(auto &pair: similarPairs) {
            map[pair[0]].insert(pair[1]);
            map[pair[1]].insert(pair[0]);
        }

        for(int i = 0; i < sentence1.size(); i++) {
            if(sentence1[i] == sentence2[i]) {
                continue;
            }

            if(!map.contains(sentence1[i])) {
                return false;
            }
            if(!map[sentence1[i]].contains(sentence2[i])) {
                return false;
            }
        }
        return true;
    }
};

运行结果

之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!

相关推荐
刘沅7 分钟前
LeetCode 93.复原IP地址
算法·面试
Teacher.chenchong29 分钟前
基于GIS、RS、VORS模型、CCDM模型、geodetecto、GWR模型集成的生态系统健康的耦合协调分析
经验分享
黑不溜秋的35 分钟前
C++ STL 容器使用的底层数据结构
c++
灵晔君1 小时前
【C++】标准模板库STL——set /multiset/map /multimap
开发语言·c++
阿里技术1 小时前
Agent 评测:方法论与体系设计
大数据·人工智能·算法
cxr8282 小时前
大语言模型上下文缓存命中率测试全场景清单
人工智能·python·算法·缓存·语言模型·自然语言处理·llm
noipp2 小时前
推荐题目:洛谷 P13554 【MX-X15-T1】奶龙龙
c语言·数据结构·c++·算法·编程·洛谷
念风2 小时前
一阶低通滤波器系数的两种计算方法
算法
geovindu2 小时前
go: Enumeration Algorithm
开发语言·后端·算法·golang·枚举算法
退休倒计时3 小时前
【每日一题】LeetCode 287. 寻找重复数 TypeScript
算法·leetcode·typescript