Code Signal_练习题_stringsRearrangement
2024-08-22 09:32:32
Given an array of equal-length strings, check if it is possible to rearrange the strings in such a way that after the rearrangement the strings at consecutive positions would differ by exactly one character.
Example
For
inputArray = ["aba", "bbb", "bab"]
, the output should bestringsRearrangement(inputArray) = false
.All rearrangements don't satisfy the description condition.
For
inputArray = ["ab", "bb", "aa"]
, the output should bestringsRearrangement(inputArray) = true
.Strings can be rearranged in the following way:
"aa", "ab", "bb"
.
不会做....
import itertools
def stringsRearrangement(inputArray):
def f(x, y):
c = 0
for i in range(len(x)):
if x[i] != y[i]:
c += 1
if c == 1:
return True
return False
for k in itertools.permutations(inputArray, len(inputArray)):
r = True
for i in range(len(k) - 1):
if not f(k[i], k[i + 1]):
r = False
if r:
return True
return False
膜拜大佬
最新文章
- 【转】Redis入门
- PostgreSQL-constraint
- Android入门(一):Android发展史
- LeetCode Find the Celebrity
- HD2025查找最大元素
- paramiko模块实现堡垒机
- ThinkPHP - 扩展个人类库 - 以验证码类为例子
- 【iOS发展-81】setNeedsDisplay刷新显卡,并CADisplayLink它用来模拟计时器效果
- 假设在本地搭一个server和mysql数据库环境,假设使用java来訪问数据库
- maven自动部署项目以及常见问题解决
- Atitti mybatis的单元测试attilax总结
- Mybatis自动生成实体类,映射文件,dao
- Django具体操作(五)
- html中引入调用另一个公用html模板文件的方法
- Win7去掉桌面图标小箭头
- [原][译][lua][luabridge]一个简单的luabridge与c++例子结合例子
- 取Mac地址
- 4514: [Sdoi2016]数字配对
- C/C++ 下mysql应用封装(连接增删改查)
- watch和computed的用法区别是什么?