-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
旋转数组 #3
Labels
Comments
|
你的第一个是O(n)了吧 |
@AshaLiu 你这招首尾相连不错呀 |
循环链表完美解决 |
list.concat(list.splice(0, k)) |
arr.splice(-k).concat(arr); 这样可以吧? |
你这样如果k大于数组长度呢 |
var arr = [1,2,3,4,5,6,7];
var k = 10;
var val = k % arr.length;
arr.splice(-val).concat(arr);
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。
示例 1:
示例 2:
说明:
尽可能想出更多的解决方案,至少有三种不同的方法可以解决这个问题。
要求使用空间复杂度为 O(1) 的原地算法。
算法
方法1
方法2
方法3
The text was updated successfully, but these errors were encountered: