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. scanf的拓展用法——匹配特定字符

    scanf的基本用法除了常规的输入操作外还有一些特殊的用法,使用这些用法可以很方便的在输入中读取想要的数据 1.限制输入数据的长度 这个应该算不上拓展用法,大多数读者应该都曾经使用过,这里简单提一下 ...

  2. 【xsy2506】 bipartite 并查集+线段树

    题目大意:有$n$个点,你需要操作$m$次.每次操作为加入/删除一条边. 问你每次操作后,这$n$个点构成的图是否是二分图. 数据范围:$n,m≤10^5$. 此题并没有强制在线,考虑离线做法. 一条 ...

  3. python高并发?

    参考: https://yunsonbai.top/

  4. odoo开发笔记 -- odoo10 视图界面根据字段状态,动态隐藏创建&编辑按钮

    场景描述: 解决方式: 网络搜索,vnsoft_form_hide_edit 找到了这个odoo8的模块, odoo10语法和视图界面有新的变化,所以需要修改一些地方,感兴趣的小伙伴可以对比下两个代码 ...

  5. 【Canal源码分析】client工作过程

    client的工作过程,需要我们自己去编写对应的逻辑,我们目前只能从example写的例子来看.目前examle中提供了两个例子,一个是单机的,一个是集群的cluster,我们后续如果需要进行开发的话 ...

  6. 【原创】贡献一个项目中用到的js身份证验证-超级准!!!

    前言 百度百科解释:身份证号码 首先贡献一个大神的链接:js验证身份证超准 代码 function checkIdcard(idcard) { var Errors = new Array( &quo ...

  7. Visual Studio最好用的快捷键(你最喜欢哪个)

    每次在网上搜关于VS有哪些常用快捷键的时候,出来的永远是一串长的不能再长的列表,完全没体现出“常用”二字,每次看完前面几个就看不下去了,相信大家都 有这种感觉.其实我们平时用的真的只有很少的一部分,借 ...

  8. springmvc json 406

    spring 4.0 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="ht ...

  9. 基于C++ Qt实现的红色警戒3修改器

    前言 这部修改器制作有一段时间了,但是一直没出教程.今天利用周末空闲写篇教程,给后来者指路的同时也加深自己对游戏修改器的理解,大佬就随便看看吧 浏览了一下网络,形形色色的单机游戏修改器教程,但是基本只 ...

  10. HDU 1535 Invitation Cards(逆向思维+邻接表+优先队列的Dijkstra算法)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1535 Problem Description In the age of television, n ...