Notice
Recent Posts
Recent Comments
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

CHIqueen

[Intro] Are Similar? 본문

프로그래밍/CodeSignal

[Intro] Are Similar?

CHIqueen 2020. 3. 17. 16:05

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