[HackerRank][Python3] Minimum Swaps 2
2018. 7. 6. 03:23 |
프로그래밍/HackerRank
Problem :
https://www.hackerrank.com/challenges/minimum-swaps-2/problem
My Solution :
#!/usr/bin/env python3 def minimumSwaps(arr): i, swap = -1, 0 while i < len(arr)-1: i += 1 if arr[i] == i+1: continue j = arr[i]-1 arr[j], arr[i] = arr[i], arr[j] swap += 1 i -= 1 return swap n = int(input()) arr = list(map(int, input().rstrip().split())) res = minimumSwaps(arr) print(res)
'프로그래밍 > HackerRank' 카테고리의 다른 글
[HackerRank][Python3] Frequency Queries (0) | 2018.07.13 |
---|---|
[HackerRank][Python3] Sherlock and Anagrams (0) | 2018.07.12 |
[HackerRank][Python3] Array Manipulation (0) | 2018.07.09 |
[HackerRank][Python3] New Year Chaos (0) | 2018.07.07 |
[HackerRank][Python3] Is This a Binary Search Tree? (2) | 2018.06.25 |
[HackerRank][Python3] Candies (0) | 2018.06.14 |
[HackerRank][Python3] Two Characters (0) | 2018.06.11 |
[HackerRank][Python3] Append and Delete (0) | 2018.06.10 |
최근에 달린 댓글 최근에 달린 댓글