当前位置: 首页 > news >正文

C++ | Leetcode C++题解之第290题单词规律

题目:

题解:

class Solution {
public:bool wordPattern(string pattern, string str) {unordered_map<string, char> str2ch;unordered_map<char, string> ch2str;int m = str.length();int i = 0;for (auto ch : pattern) {if (i >= m) {return false;}int j = i;while (j < m && str[j] != ' ') j++;const string &tmp = str.substr(i, j - i);if (str2ch.count(tmp) && str2ch[tmp] != ch) {return false;}if (ch2str.count(ch) && ch2str[ch] != tmp) {return false;}str2ch[tmp] = ch;ch2str[ch] = tmp;i = j + 1;}return i >= m;}
};
http://www.lryc.cn/news/406843.html

相关文章:

  • Pytorch使用教学7-张量的广播
  • 生成式AI:对话系统(Chat)与自主代理(Agent)的和谐共舞
  • 唯众物联网(IOT)全功能综合实训教学解决方案
  • 24证券从业考试报名『个人信息表』填写模板❗
  • 深度学习系列70:模型部署torchserve
  • 算法日记day 20(中序后序遍历序列构造二叉树|最大、合并、搜索二叉树)
  • 【科研】# Taylor Francis 论文 LaTeX template模版 及 Word模版
  • Linux网络配置及常见命令!
  • linux之shell脚本实战
  • 文件上传漏洞(ctfshow web151-161)
  • 小猪佩奇.js
  • 人工智能AI合集:Ollama部署对话语言大模型-网页访问
  • CentOS搭建Apache服务器
  • CDGA|数据治理:安全如何贯穿数据供给、流通、使用全过程
  • 32单片机bootloader程序
  • MongoDB - 数组更新操作符:$、$[]、$pop、$pull、$push、$each、$sort、$slice、$position
  • 多GPU并行处理[任务分配、进程调度、资源管理、负载均衡]
  • 项目部署到服务器
  • Idea2024 创建Meaven项目没有src文件夹
  • LeetCode 2766.重新放置石块:哈希表
  • 基于STM32的农业大棚温湿度采集控制系统的设计
  • go语言的命名规则
  • 新增ClamAV病毒扫描功能、支持Java和Go运行环境,1Panel开源面板v1.10.12版本发布
  • Windows通过命令查看mac : getmac
  • Android笔试面试题AI答之Android系统与综合类(1)
  • 【Android】数据存储方案——文件存储、SharedPreferences、SQLite数据库用法总结
  • 抖音矩阵管理系统功能说明:一站式掌握
  • 旅游卡使用指南及常见疑问解答
  • 【MySQL篇】Percona XtraBackup标准化全库完整备份策略(第三篇,总共五篇)
  • 背单词工具(C++)