Last updated 6 years ago
class Solution { public: void rotate(vector<int>& nums, int k) { if (k == 0) { return; } k = k % nums.size(); for (int i = 0 ; i < k ; i++) { nums.insert(nums.begin(), nums.back()); nums.pop_back(); } } };