We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 434b13e + dcff324 commit 97fa6cfCopy full SHA for 97fa6cf
src/leetcode/189_rotate-array/20251106.ts
@@ -0,0 +1,14 @@
1
+/**
2
+ Do not return anything, modify nums in-place instead.
3
+ */
4
+export function rotate(nums: number[], k: number): void {
5
+ for (let i = 0; i < nums.length; i++) {
6
+ if (i + k < nums.length) {
7
+ const transferedIndex = i + k;
8
+ nums[transferedIndex] = nums[i];
9
+ } else {
10
+ const transferedIndex = i + k - nums.length;
11
12
+ }
13
14
+};
0 commit comments