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

膜拜大佬

Code Signal_练习题_stringsRearrangement的更多相关文章

  1. Code Signal_练习题_digitDegree

    Let's define digit degree of some positive integer as the number of times we need to replace this nu ...

  2. Code Signal_练习题_Knapsack Light

    You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...

  3. Code Signal_练习题_growingPlant

    Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...

  4. Code Signal_练习题_arrayMaxConsecutiveSum

    Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...

  5. Code Signal_练习题_differentSymbolsNaive

    Given a string, find the number of different characters in it. Example For s = "cabca", th ...

  6. Code Signal_练习题_firstDigit

    Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...

  7. Code Signal_练习题_extractEachKth

    Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...

  8. Code Signal_练习题_absoluteValuesSumMinimization

    Given a sorted array of integers a, find an integer x from a such that the value of abs(a[0] - x) + ...

  9. Code Signal_练习题_depositProfit

    You have deposited a specific amount of money into your bank account. Each year your balance increas ...

随机推荐

  1. Django(命名URL和URL反向解析)

    day67 参考: https://www.cnblogs.com/liwenzhou/articles/8271147.html#autoid-1-4-0 反向解析URL             本 ...

  2. postgresql-distinct on理解

    PostgreSQL 的 distinct on 的理解 对于 select distinct on , 可以利用下面的例子来理解: create table a6(id integer, name ...

  3. SQLAlchemy介绍和基本使用

    pymysql:pymysql是用Python来操作mysql的包,因此通过pip来安装,命令如下:pip3 install pymysql.如果您用的是Python 3,请安装pymysql 豆瓣源 ...

  4. SpaceSyntax【空间句法】之DepthMapX学习:第三篇 软件介绍与一般分析流程图

    上篇讲啥来着?好像讲了数据的输入以及一些核心的概念.这篇讲软件长什么样,做那几种分析的步骤如何. 博客园/B站/知乎/CSDN @秋意正寒(我觉得这一篇肯定很多盗图的,那么我在版头加个本篇地址吧)ht ...

  5. 从用户浏览器输入url到用户看到页面结果的过程,发生了什么事情?

    1.域名解析 域名解析的过程:  1).查询浏览器自身DNS缓存 2).若上面没有查找到,则搜索操作系统自身的dns缓存 3).若上面没有找到,则尝试读取hosts文件 4).若上面没有找到,向本地配 ...

  6. 使用libcurl的正确姿势

    libcurl支持访问http.ftp等各种服务器,下载图片AV什么的不在话下.但其存在多种接口,异步接口也很难以理解,到底什么样的使用姿势才是正确滴?我们来看看可用的体位: easy interfa ...

  7. sql练习(针对Mysql)

    创建表: DROP TABLE DEPT; --部门表 CREATE TABLE DEPT( DEPTNO int PRIMARY KEY, DNAME ) , --部门名称 LOC ) ---部门地 ...

  8. 深入理解Spring的ImportSelector接口

    ImportSelector接口是至spring中导入外部配置的核心接口,在SpringBoot的自动化配置和@EnableXXX(功能性注解)都有它的存在,关于SpringBoot的分析可以参考:深 ...

  9. php插入数据含有特殊符号的处理方法

    我们在向mysql写入数据时,比如: mysql_query(”update table set `title`=’kuhanzhu’s blog’”); http://www.cnblogs.com ...

  10. 读书笔记(04) - 错误监控 - JavaScript高级程序设计

    错误类型 即时运行错误 (代码错误) 资源加载错误 常见的错误 1. 类型转换错误 建议使用全等===操作符 2.数据类型错误 建议加强类型判断 // 数组倒序 function reverseSor ...