【LeetCode】290. Word Pattern (Python实现)

FMCW雷达测距原理详解:从线性调频到拍频信号的关键链路 调频连续波(FMCW)雷达是毫米波雷达中的主流技术,其核心测距思路并非直接测量电磁波往返时间,而是通过发射频率随时间线性变化的线性调频信号(chirp),将目标的距离信息巧妙编码为接收信号与发射信号之间的频率差,即拍频信号。拍频频率与目标距离严格成正比,通过混频、低通滤波和ADC采样后,再利用Range FFT即可提取该频率,进而解算出目标距离。这一机制赋予FMCW雷达低峰值功率、高距离分辨率、可同时测速测角等优势,在车载雷达、人体存在检测、工业测距等场景中广泛应用。理解从线性调频信号到拍频信号再到距离解算 阅读详情

参考链接:https://blog.csdn.net/coder_orz/article/details/51693647

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.

Example 1:

Input: pattern = "abba", str = "dog cat cat dog"
Output: true

Example 2:

Input:pattern = "abba", str = "dog cat cat fish"
Output: false

Example 3:

Input: pattern = "aaaa", str = "dog cat cat dog"
Output: false

Example 4:

Input: pattern = "abba", str = "dog dog dog dog"
Output: false

方法一:就是建立两个字典,进行双向映射检查。

class Solution(object):
    def wordPattern(self, pattern, str):
        """
        :type pattern: str
        :type str: str
        :rtype: bool
        """
        
        str_list = str.strip().split()
        if len(str_list) != len(pattern):
            return "false"

        dictmap = {}
        mapval = {}
        for i in range(len(pattern.strip())):
            if pattern[i] in dictmap.keys():
                if str_list[i] != dictmap[pattern[i]]:
                    return "false"
            else:
                #这个地方是为了双向映射的原因
                if str_list[i] in mapval:
                    return "false"
                dictmap[pattern[i]] = str_list[i]
                mapval[str_list[i]] = pattern[i]
        return "true"

方法二:记录每个字符和单词出现的第一个位置,使得每个字符和单词两边出现的第一次位置都相同时,就能保证双射。

class Solution(object):
    def wordPattern(self, pattern, str):
        """
        :type pattern: str
        :type str: str
        :rtype: bool
        """
        

        words = str.split(' ')
        if len(words) != len(pattern):
            return False
        if map(pattern.find, pattern) == map(words.index, words):
            return "true"
        else:
            return "false"

方法三:('a',‘dog’)类似这种建立映射体系,这个长度和pattern及str中去重后的长度是相等的。

class Solution(object):
    def wordPattern(self, pattern, str):
        """
        :type pattern: str
        :type str: str
        :rtype: bool
        """
        
        words = str.split(' ')
        if len(words) != len(pattern):
            return False
        return len(set(pattern)) == len(set(words)) == len(set(zip(pattern, words)))

 

 

Isograph Reliability Workbench 14实战:从零构建故障树分析模型 本文以“马达不转”为例,手把手教你使用Isograph Reliability Workbench 14从零构建故障树分析模型。内容涵盖创建工程、定义顶事件、添加逻辑门与基础事件等核心步骤,并介绍了模型检查与定性定量分析,帮助你系统掌握这一强大的可靠性工程工具。 阅读详情

相关推荐

网格自适应_Comsol案例解析17:自适应网格的使用

本期导读自适应网格细化有许多优势,比如可以不用对网格进行全局加密,增加计算精度,又会降低求解自由度。本期仍然以气泡上升案例为例,在两相流模块中使用自适应网格。【打开案例模型】【修改网格】适当让气泡边界加密,注意,曲率因子越小,曲线上的网格越密【添加自适应网格】使用默认的参数即可,这里的误差指示器用的是水平集phi。可以根据具体求解模型选择适当的自变量作为误差指示器。【口诀】默认的一般是最...

weixin_28726871的博客 5694

Leetcode 290. Word Pattern & 291. Word Pattern II (python)

Leetcode 290. Word Pattern & 291. Word Pattern IIword pattern题目解法:双hashmapword pattern II题目:解法:双hashmap+backtracking word pattern 题目 解法:双hashmap 判断他们是否matching的关键在于,pattern中的某个字母和s中的单词是不是双向1-1对应的。要表达这种双向1-1对应的关系可以用两个字典,每个字典表示一种映射方向 class Solution:

qq_37821701的博客 858

trae使用playwright MCP方法流程

trae使用playwright MCP方法流程

MAILLIBIN的专栏 1686

290. Word Pattern

题目大意: 给定两个字符串pattern和str,判断str的模式是否和pattern一直思路: 一开始没什么思路,直接写了两层for循环,O(n2)的代码辣眼睛,提交坐等超时,然而并没有超时,持续懵逼中。Python代码 arr = str.split(' ') print(arr) if len(pattern) != len(arr):

两鬓已不能斑白的专栏 604

NXP实战笔记(五):S32K3xx基于RTD-SDK在S32DS上配置ADC的硬件触发同步采样与软件采样过程

恩智浦 S32K3xx 系列汽车微控制器器件具有 15 位分辨率逐次逼近模数转换器(SAR ADC),可用于模拟输入信号的采集和数字化。-15 位的分辨率。转换数据总是15 位宽,与所选转换分辨率无关(每转换数据 14、12、10、8 个有效位,减少这个数字会加快数据转换,因为 SAR 算法的执行步骤会更少)。-每个输入通道捕获的转换数据放在单独寄存器中。-可使用“ 平均法” 提高精度,即通过计算最高 32 次转换数据的平均数来提供最终结果。-正常转换触发转换多个。

梦想技术家 3860

STM32+HX711实战:5分钟搞定拉力传感器数据采集(附完整代码)

本文详细介绍了如何使用STM32微控制器和HX711模数转换器快速搭建高精度拉力测量系统。通过硬件连接指南、驱动实现代码和校准方法,帮助开发者在5分钟内完成拉力传感器数据采集,适用于工业自动化和消费电子等场景。

y7z8a9的博客 884

python 密码学 第一版 第二版_python 密码学编程 -- 2

接上一篇随笔*********************************************************************        quote : "http://inventwithpython.com/"              **        python-version : 2.7.11                      **********...

weixin_39845347的博客 507

足球赛事数据API:开发者生存指南(附真实踩坑记录)

作为一个既爱看球又爱写代码的老宅男,我这些年用过的足球API比看过的比赛还多。从最初被各种API文档折磨到怀疑人生,到现在能闭着眼睛调接口,中间的血泪史够写本书了。今天就把这些经验(和教训)分享给各位同好,特别是那些正在为"老板要做个足球App"而秃头的同行们。文档清晰免费层可用响应格式规范API-Sports免费额度大方支持GraphQL有中文文档(难得!Sportmonks数据全面有Webhook支持按需付费。

Happy0970的博客 2222

LeetCode:290(Python)—— 单词规律(简单)

概述:给定一种规律 pattern和一个字符串s,判断 s是否遵循相同的规律。

m0_61661179的博客 3万+

ABAP Development Tools 3.62 搭配 Claude Code,已经从旁路方案走到了 SAP 官方 MCP 路线

截至2026年10月,ABAP Development Tools 3.62已通过官方ADT MCP Server实现与Claude Code的深度集成。Claude Code作为MCP客户端,可直接调用ABAP Repository的完整开发能力,包括读取、创建、修改、激活对象及运行ATC、ABAP Unit等操作,无需依赖本地文件或第三方封装。SAP新增的精准编辑(abap_object_edit_file)和符号检索(abap_object_get_document_symbols)工具,有效控制风险

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 67

图解目标检测 之 YOLO 算法 最全原理详解

YOLO 一.背景 YOLO(You Only Look Once: Unified, Real-Time Object Detection),是Joseph Redmon和Ali Farhadi等人于2015年提出的基于单个神经网络的目标检测系统。在2017年CVPR上,Joseph Redmon和Ali Farhadi又发表的YOLO 2,进一步提高了检测的精度和速度。 二.YOLO算法的网...

DFCED的博客 26万+

290. Word Pattern [easy] (Python)

题目链接https://leetcode.com/problems/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

Coder_Orz的博客 5368

【数据集】中国陆地生态系统通量观测网 ChinaFLUX

【数据集】中国陆地生态系统通量观测网 ChinaFLUX

WW、forever的博客 217

Leetcode 290.单词规律(Word Pattern)

Leetcode 290.单词规律 1 题目描述(Leetcode题目链接)   给定一种规律 pattern 和一个字符串 str ,判断 str 是否遵循相同的规律。 这里的 遵循 指完全匹配,例如, pattern 里的每个字母和字符串 str 中的每个非空单词之间存在着双向连接的对应规律。 输入: pattern = "abba", str = "dog cat cat dog" 输出: true 输入:pattern = "abba", str = "dog cat cat fish" 输出:

qq_39378221的博客 278

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

leetcode 290: Word Pattern

Word Pattern Total Accepted: 1733 Total Submissions: 6204 Difficulty: Easy Given a pattern and a string str, find if str follows the same pattern. Examples: pattern = "abba", s

西施豆腐渣 6845

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Leetcode【290】Word Pattern(Python)

输入: pattern = "abba", str = "dog cat cat dog" 输出: true 很简单,判断目标字符串是否匹配给定的模式 这里用到了python的map函数,生成映射关系 class Solution(object): def wordPattern(self, pattern, str): """ :type pat...

ssjdoudou的博客 6947

蓝牙模块HM-10手册

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

[LeetCode]290. Word Pattern ★

每天一道编程题题目描述样例python解法 题目描述 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-...

xingyu97的博客 149

LeetCode Python 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. Exampl...

Shawn的博客 430

LeetCode探索之旅(77)-290Word Pattern

今天继续刷LeetCode,第290题,判断两个字符串模式是否相等。 分析: 通过istringstream将第二个字符串的每个单词进行分开,同时比较两个字符串中对应位置map映射的结果是否相等。如果相等,就重新赋值,不等就返回false。 问题: 1、map映射的使用; 2、set的使用; 3、Python中zip的使用。 附上C++代码: class Solution { public: ...

JerryZengZ的博客 146

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

常山赵子龙 174

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.

无名山丘,崛起成峰 1262

LeetCode—— 290 单词规律

问题描述 给定一种规律 pattern和一个字符串str,判断 str 是否遵循相同的规律。 这里的遵循指完全匹配,例如,pattern里的每个字母和字符串str中的每个非空单词之间存在着双向连接的对应规律。 示例1: 输入: pattern = "abba", str = "dog cat cat dog" 输出: true 示例 2: 输入:pattern = "a...

CSDN的博客 295

leetcode 290. Word Pattern

1.题目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.Example

沐沐余风的专栏 302

【leetcode】290. Word Pattern

题目如下: 解题思路:本题的关键是pattern和word之间必须是一对一的关系。因此需要建立pattern->word和word->pattern两种映射,这两种映射可用两个字典分别保存。 代码如下: class Solution(object): def wordPattern(self, pattern, str): """ ...

weixin_34000916的博客 72

【leetcode】290. Word Pattern(Python & C++)

290. Word Pattern题目链接290.1 题目描述: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 n

I am what i am 759

leetcode290.word pattern

def wordPattern(pattern, str): # res = str.split() # # return list(map(pattern.index, pattern)) == list(map(res.index, res)) # # words = str.split(' ') if len(pattern) != len(words): return False hashmap = {} m.

技术奇的默默积累 215
上一篇: 判断链表是否存在环,输出第一次的环的入口地址
下一篇: 正则匹配ipv4和ipv6,判断ipv4和ipv6的合法性
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值