290. Word Pattern
来源:互联网 发布:局域网桌面监控软件 编辑:程序博客网 时间:2024/06/15 23:57
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:
- pattern =
"abba"
, str ="dog cat cat dog"
should return true. - pattern =
"abba"
, str ="dog cat cat fish"
should return false. - pattern =
"aaaa"
, str ="dog cat cat dog"
should return false. - pattern =
"abba"
, str ="dog dog dog dog"
should return false.
code:
class Solution(object):
def wordPattern(self, pattern, str):
"""
:type pattern: str
:type str: str
:rtype: bool
"""
a=str.split()
return [a.index(x) for x in a]==[pattern.find(y) for y in pattern]
阅读全文
0 0
- 【leetcode】290. Word Pattern
- 【leetcode】290. Word Pattern
- 290. Word Pattern
- 290. Word Pattern
- 290. Word Pattern
- 290. Word Pattern
- 290. Word Pattern LeetCode
- 290. Word Pattern
- 290. Word Pattern
- 290. Word Pattern
- 290. Word Pattern
- 290. Word Pattern
- Leetcode 290. Word Pattern
- 290. Word Pattern
- 【LeetCode】290. Word Pattern
- 290. Word Pattern
- LeetCode-290. Word Pattern
- LeetCode *** 290. Word Pattern
- 读取字节太多导致STM32读取TF错误
- 不输入密码ssh直接登录Linux主机的实践与总结
- top-1 recall precise解释
- HDU2571(dp)
- C++ using namespace std 详解 与 命名空间的使用
- 290. Word Pattern
- JAVA冒泡排序衍生求最大最小值
- linux下删除指定文件夹目录下指定的文件名命令( find 指定的文件夹/ -name this.html~ |xargs rm -rf)
- PhantomJS简介及安装
- 过滤器跳转的页面显示问题
- 案例----新闻客户端
- 需求性质:什么是伴生性需求
- js中的apply和call函数
- 阿里巴巴Json工具-Fastjson讲解