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 be
      stringsRearrangement(inputArray) = false.

      All rearrangements don't satisfy the description condition.

    • For inputArray = ["ab", "bb", "aa"], the output should be
      stringsRearrangement(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

膜拜大佬

最新文章

  1. 【转】Redis入门
  2. PostgreSQL-constraint
  3. Android入门(一):Android发展史
  4. LeetCode Find the Celebrity
  5. HD2025查找最大元素
  6. paramiko模块实现堡垒机
  7. ThinkPHP - 扩展个人类库 - 以验证码类为例子
  8. 【iOS发展-81】setNeedsDisplay刷新显卡,并CADisplayLink它用来模拟计时器效果
  9. 假设在本地搭一个server和mysql数据库环境,假设使用java来訪问数据库
  10. maven自动部署项目以及常见问题解决
  11. Atitti mybatis的单元测试attilax总结
  12. Mybatis自动生成实体类,映射文件,dao
  13. Django具体操作(五)
  14. html中引入调用另一个公用html模板文件的方法
  15. Win7去掉桌面图标小箭头
  16. [原][译][lua][luabridge]一个简单的luabridge与c++例子结合例子
  17. 取Mac地址
  18. 4514: [Sdoi2016]数字配对
  19. C/C++ 下mysql应用封装(连接增删改查)
  20. watch和computed的用法区别是什么?

热门文章

  1. Hbuilder用ajax连接阿里服务器上的servlet以及注意事项
  2. 5_Python OOP
  3. [Leetcode]315.计算右侧小于当前元素的个数 (6种方法)
  4. redis之事务
  5. C# 添加修改防火墙端口及程序
  6. PyCharm下载与激活
  7. Android初识Helloworld
  8. python中@staticmethod与@classmethod
  9. Struts框架核心工作流程与原理
  10. Sharding-jdbc(一)分库分表理解