标签:count public art col start while tco 解题思路 leetcode
旋转数组
解题思路:环形旋转
class Solution { public void rotate(int[] nums, int k) { int len = nums.length; k = k%len; int count = 0; int temp = 0; int start = 0; int i = 0; int swp = 0; while(count<len){ i=start; temp = nums[i]; do{ swp = nums[(i+k)%len]; nums[(i+k)%len] = temp; temp = swp; ++count; i=(i+k)%len; } while(i!=start); ++start; } } }
标签:count public art col start while tco 解题思路 leetcode
原文地址:https://www.cnblogs.com/erdanyang/p/11497292.html