2017年2月13日 星期一

【Python】Codility in Python : Lesson 2 - Arrays【CyclicRotation】

Arrays 練習題的第二題題目是【OddOccurrencesInArray】
Task : Rotate an array to the right by a given number of steps.

方法一:使用 pop & insert 的簡易方式

def solutionByPop(A, K):
  if(K > 0 and len(A) > 1):
    for i in range(0, K):
      A.insert(0, A.pop())
  return A

完整練習題 source code 請參閱:github

沒有留言:

張貼留言