CHIqueen
[Intro] Are Similar? 본문
Two arrays are called similar if one can be obtained from another by swapping at most one pair of elements in one of the arrays.
Given two arrays a and b, check whether they are similar.
def areSimilar(a, b):
return sorted(a)==sorted(b) and sum([c!=d for c,d in zip(a,b)])<=2
한번만 바꿀수 있으니 두 리스트를 비교했을때 다른 요소를 가지고 있는건 2개 이하여야 한다.
'프로그래밍 > CodeSignal' 카테고리의 다른 글
[Intro] areEquallyStrong (0) | 2020.03.17 |
---|---|
[Intro] palindromeRearranging (0) | 2020.03.17 |
[Intro] Add Border (0) | 2020.03.17 |
[Intro] alternationSums (0) | 2020.03.17 |
[Intro] reverseParenthese (0) | 2020.03.11 |
Comments