Skip to content

Commit 97fa6cf

Browse files
authored
Merge pull request #17 from argondev22/20251106/16-189-rotate-array
Create 20251106.ts
2 parents 434b13e + dcff324 commit 97fa6cf

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
nums[transferedIndex] = nums[i];
12+
}
13+
}
14+
};

0 commit comments

Comments
 (0)