leetcode 87scamblestring
来源:互联网 发布:软件开发工程师前景 编辑:程序博客网 时间:2024/05/18 02:52
class Solution(object):
def isScramble(self, s1, s2):
"""
:type s1: str
:type s2: str
:rtype: bool
"""
n, m = len(s1), len(s2)
if n != m or sorted(s1) != sorted(s2):
return False
if n < 4 or s1 == s2:
return True
f = self.isScramble
for i in range(1, n):
if f(s1[:i], s2[:i]) and f(s1[i:], s2[i:]) or \
f(s1[:i], s2[-i:]) and f(s1[i:], s2[:-i]):
return True
return False
def isScramble(self, s1, s2):
"""
:type s1: str
:type s2: str
:rtype: bool
"""
n, m = len(s1), len(s2)
if n != m or sorted(s1) != sorted(s2):
return False
if n < 4 or s1 == s2:
return True
f = self.isScramble
for i in range(1, n):
if f(s1[:i], s2[:i]) and f(s1[i:], s2[i:]) or \
f(s1[:i], s2[-i:]) and f(s1[i:], s2[:-i]):
return True
return False
0 0
- leetcode 87scamblestring
- LeetCode(87)Partition List
- LeetCode: Scramble String [87]
- LeetCode 87 Add Binary
- LeetCode 87 Scramble String
- [leetcode 87] Scramble String
- leetcode 87: Scramble String
- leetcode 87: Scramble String
- leetcode 87:Scramble String
- *leetcode #87 in cpp
- LeetCode #87: Scramble String
- Leetcode 87 Scramble String
- leetCode练习(87)
- LeetCode 87 Scramble String
- [Leetcode] 97, 168, 87
- leetcode
- [leetcode]
- LeetCode
- Myeclipse解决乱码
- 2017为什么退出CSDN的博客转向阿里云博客
- 【模拟】洛谷 P1055 ISBN号码
- 高性能键值对系统Redis介绍及安装详解
- (转)5.4 双缓冲技术(Double Buffering)-2
- leetcode 87scamblestring
- Windows10 内置 Linux 子系统
- 360安全浏览器新标签页被2345流氓网址劫持的解决办法
- javascript程序的执行与顺序详解
- ffmpeg 常用命令
- (转)5.4 双缓冲技术(Double Buffering)-3
- C++第5次实验:【项目五5】数组分离
- Android Notification常见样式总结
- C++第五次实验报告