HackerRank: New Year Chaos
Tags: hackerrank, 紮馬步
寫到這題超級應景阿~~~ Happy New Year~~ HAHAHA!

New Year Chaos
- 
     
- 
     
- 
    python  
- 這不會過 哭哭~~
- 我真的只想的到 Chaotic的情況~
 
# Complete the minimumBribes function below.
def minimumBribes(q):
    origin_list = [ i for i in range(1, len(q) +1)]
    move_count = 0
    for i in range(len(q)):
        if q[i] - i > 3 :
            print ('Too chaotic')
            return 
        move_step = origin_list[i] - q[i]
        if move_step > 0:
            move_count += move_step
    print(move_count)
- 看看高手怎麼解
- 
    python - 還是沒有全懂… 但是卡一天了 哈哈哈 XDDD
 
# Complete the minimumBribes function below.
def minimumBribes(q):
    move_count = 0
    for i in range(len(q)):
        if q[i] - i > 3 :
            print ('Too chaotic')
            return 
        
        for j in range(max(0, q[i] - 2), i):
            if q[j] > q[i]:
                move_count +=1
    print(move_count)