Array Left Rotation
Posted johnnyzhao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Array Left Rotation相关的知识,希望对你有一定的参考价值。
package arrays /** * https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem * * A left rotation operation on an array shifts each of the array‘s elements unit to the left. * For example, if left rotations are performed on array , then the array would become . Given an array of integers and a number, perform left rotations on the array. Return the updated array to be printed as a single line of space-separated integers. * */ class LeftRotation { fun rotLeft(a: Array<Int>, d: Int): Array<Int> { val size = a.size val result = Array<Int>(size, { 0 }) //get the start point to rotated val mod = d % size for (i in a.indices) { val index = (i + mod) % size result.set(i, a[index]) } return result } }
以上是关于Array Left Rotation的主要内容,如果未能解决你的问题,请参考以下文章
js代码片段: utils/lcoalStorage/cookie
[TIA PORTAL][CONVERT] Convert Char Array to DInt...DInt to Char Array..Useful and easy function(代码片段