标签:class core ret nbsp oid ++ etc || art
注意k可能大于length
class Solution { public: void rotate(vector<int>& nums, int k) { int length = nums.size(); if(length <= 1 || k <= 0) return; k = k%length; rotate_core(nums,0,length-1); rotate_core(nums,0,k-1); rotate_core(nums,k,length-1); return; } void rotate_core(vector<int>& nums,int start,int end){ while(start < end){ int tmp = nums[start]; nums[start] = nums[end]; nums[end] = tmp; start++; end--; } return; } };
标签:class core ret nbsp oid ++ etc || art
原文地址:https://www.cnblogs.com/ymjyqsx/p/9651537.html