LeetCode Oj 290. Word Pattern

HyperMesh 2025新功能尝鲜:用Volume Tetramesh一键生成工业级四面体网格 HyperMesh 2025推出的Volume Tetramesh功能,通过“体到体”的全新范式,实现了工业级四面体网格的一键生成。该功能利用Proximity与Curvature参数智能识别并加密几何特征,将工程师从繁琐的几何清理和表面网格划分中解放出来,在保证网格质量的同时,显著提升了前处理效率,尤其适用于发动机缸体等复杂模型的仿真分析。 阅读详情

290. Word Pattern

 
  My Submissions
  • Total Accepted: 43861
  • Total Submissions: 144885
  • Difficulty: Easy

Given a pattern and a string str, find if str follows the same pattern.

Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.

Examples:

  1. pattern = "abba", str = "dog cat cat dog" should return true.
  2. pattern = "abba", str = "dog cat cat fish" should return false.
  3. pattern = "aaaa", str = "dog cat cat dog" should return false.
  4. pattern = "abba", str = "dog dog dog dog" should return false.

Notes:
You may assume pattern contains only lowercase letters, and str contains lowercase letters separated by a single space.

Credits:



class Solution {
public:
    bool wordPattern(string pattern, string str) {
        int vis[500];
        memset(vis , 0, sizeof(vis));
        map<int,string>mp;
        map<string,int>b_mp;
        vector<int>a;
        vector<string>b;
        for(int i=0;i<pattern.length();i++)
           a.push_back(pattern[i]);
        string t="";
        str=str+" ";
        for(int i=0;i<str.length();i++)
           if(str[i]==' ')
            {
                b.push_back(t);
                t="";
            }
           else
            {
                 t=t+str[i];
            }
    if(a.size()!=b.size()) return false;

    for(int i=0;i<a.size();i++)
        {
            if(!vis[a[i]])
            {
                if(b_mp[b[i]]) return false;

                vis[a[i]]=1;
                mp[a[i]]=b[i];
                vis[a[i]]=1;
                b_mp[b[i]]=a[i];
            }
            else
            {
                if(mp[a[i]]!=b[i]) return false;
            }
        }
    return true;
    }
};


从信号到振镜:STM32F103 + XY2-100协议 + AM26LS31芯片的激光打标/雕刻系统信号链搭建指南 本文详细介绍了基于STM32F103微控制器和XY2-100协议的激光打标/雕刻系统信号链搭建方法。从数字振镜控制协议解析、AM26LS31差分驱动电路设计到信号完整性优化,提供了一套完整的解决方案,帮助工程师实现高精度激光控制系统的开发与调试。 阅读详情

相关推荐

压电陶瓷传感器避坑指南:实测阻抗匹配对信号输出的影响(附示波器调试技巧)

本文深入探讨压电陶瓷传感器在工业振动监测中的阻抗匹配问题,通过等效电路模型和实测数据揭示负载阻抗对信号输出的关键影响。文章提供从元件选型到示波器调试的完整解决方案,特别强调100kΩ以上负载阻抗的重要性,并分享JFET缓冲器设计和PCB布局的实用技巧,帮助工程师避免信号失真和输出不稳定问题。

ooo22的博客 516

LeetCode:Word Pattern

Word Pattern Total Accepted: 21299 Total Submissions: 77656 Difficulty: Easy Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match,

walker lee 525

[学习笔记]Esp32 + 4G模块,随身wifi,ppp拨号上网

Esp32S3 + 4G模块制作随身WIFI教程

weixin_45595548的博客 7413

290. Word Pattern(技巧:记录当前位置来判断两个字符串是否符合)

Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.

u010005161的博客 1191

5分钟搞懂双目相机标定:从棋盘格到3D点云的完整流程(附Python代码)

本文详细介绍了双目相机标定的完整流程,从棋盘格准备到3D点云生成,涵盖单目标定、双目标定、立体校正、视差计算等关键步骤。通过Python代码示例,帮助读者快速掌握双目立体视觉技术,实现高精度的3D重建。特别适合机器人导航、工业检测等应用场景。

weixin_29100399的博客 585

ck3m多轴运动控制器笔记1:电机的配置与注意事项

利用PMAC(CK3M)运动控制器来实现对电机的控制,对具体的配置流程和注意事项讲解

p975468132的博客 4641

leetcode Word Pattern

map

GadyPu的专栏 487

三相电机控制入门:端电压、相电压、线电压到底怎么测?(附实测波形对比)

本文为三相电机控制初学者提供了端电压、相电压和线电压的完整测量指南。通过厘清三者的物理定义与测量方法,详细讲解了如何搭建虚拟星形点电路,并对比分析了方波、SPWM和SVPWM三种主流控制模式下关键电压波形的核心特征与差异,帮助工程师掌握正确的示波器测量与波形解读技巧。

oauth7security的博客 650

LeetCode题解:Word Pattern

Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.Examples:

追风筝的吃货,汪~ 615

ERA5 数据集下载(2025最新 可运行)

众所周知,ERA5数据集经过了更新,尤其是在API访问和下载方式上发生了变化。2025年版的ERA5数据集为气象研究人员提供了更高质量的历史气象数据。本文将介绍如何通过新的API接口下载最新的ERA5数据集。

m0_72141699的博客 3592

出现Command ‘vim‘ is available in the following places,vim: command not found等解决方法

内置命令无法识别,说明系统变量有误,导致无法识别,既然系统变量有误,将其注释或者更改为正确的即可,但是现在打不开,又怎么注释掉。替换vim来打开编辑,打开之前错误的全局变量文件,发现变量有误,要么注释要么改为。系统变量有全局变量(通过命令行printenv或者echo)和局部变量。对应通过vim修改错误的变量文件,不然source也无法让配置文件生效。本身vim是系统内置的命令,连vim都出现问题。修改为正确的即可,之后还需要重启服务器,使用。之后即可成功,通过即可查看命令是否有写入。...

码农研究僧的博客 5883

LeetCode290——Word Pattern

Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str. Ex

代码菌的blog 822

【车载以太网】Eth Stack Bringup

摘要:本文基于AUTOSAR架构,详细介绍了在TC3xx硬件平台上实现EthStack Bringup的全过程。作者通过配置MCAL和Davinci工具,完成了EthTrcv、Eth、EthIf、EthSM和TcpIp等模块的集成,并解决了16字节内存对齐和以太网速率不匹配等问题。最终实现了PC端与开发板的Ping通,并通过WireShark验证了数据包收发。文章总结了调试中的关键问题与解决方案,强调了实践的重要性,为后续EthStack的深入分析奠定了基础。

qq_36056498的博客 180

Leetcode 算法题24

234. Palindrome Linked List判断一个链表是否左右对称,用O(n)的时间和O(1)的内存我的代码:# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None clas...

li5226966的博客 283

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Word Pattern问题及解法

问题描述: Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in

刘天的博客 1325

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Word Pattern 双重映射

Word Pattern Given a pattern and a string str, find if str follows the same pattern. Examples: pattern = "abba", str = "dog cat cat dog" should return true.pattern = "abba", str = "

小人物的草稿本 1187

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

leetcode笔记:Word Pattern

题目的大意是,给出一组模式(pattern)和一个字符串(str),判断字符串是否与模式相匹配,并给出了几个例子。

liyuefeilong的专栏 1947

LeetCode290 Word Pattern 同构字符串

题目要求: Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.Exam

ncst 347

Word Pattern

Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.

码农少年专栏 333

leetcode | Word Pattern

Given a pattern and a string str, find if str follows the same pattern. Examples: pattern = "abba", str = "dog cat cat dog" should return true.pattern = "abba", str = "dog cat cat fish" 

weizaishouex2010的专栏 1661

LEETCODE 290

Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.

zj443108444的博客 465

[leetcode] 290. Word Pattern

Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.

TstsUgeg的博客 404

LeetCode 290 Word Pattern

Word Pattern Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty

我要加油了,因为我还有很多NB的梦想! 475

​LeetCode刷题实战291:单词规律II

算法的重要性,我就不多说了吧,想去大厂,就必须要经过基础知识和业务逻辑面试+算法面试。所以,为了提高大家的算法能力,这个公众号后续每天带大家做一道算法题,题目就从LeetCode上面选 !...

程序IT圈 382

【leetcode】290. Word Pattern

利用map解决一一对应

小do在努力 2092
上一篇: git 基本操作
下一篇: 234. Palindrome Linked List(判断链表是不是回文的)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值