MCPcopy Create free account
hub / github.com/Hsinha11/Leetcode-solutions / rotate

Method rotate

189-Rotate-Array/189_Rotate_Array.cpp:7–19  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5class Solution {
6public:
7 void rotate(vector<int>& nums, int k) {
8 int n = nums.size();
9 k = k % n;
10 if (k == 0) return;
11
12 vector<int> temp(nums.end() - k, nums.end());
13 for (int i = n - k - 1; i >= 0; i--) {
14 nums[i + k] = nums[i];
15 }
16 for (int i = 0; i < k; i++) {
17 nums[i] = temp[i];
18 }
19 }
20};
21
22void printVector(const vector<int>& v) {

Callers 1

mainFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected