public void rotate(int[] nums, int k) {
if(k==1){
return ;
}
for(int i=0;i<k;i++){
moveToRight(nums);
}
}
private void moveToRight(int[] nums){
int last = nums[nums.length1];
for(int i=0;i<nums.length1;i++){
nums[i+1] = nums[i];
}
nums[0] = last;
}
Why my code appears Time Limit Exceeded? this is my code.. anyone can tell me why? thanks..

there is no assumption written that k must be less than array length.
so there is the situation where k is much greater than length with times.example: nums = {1,2,3,4,5,6,7} k = 70000000000;
in fact, the ouput is the same, each number will be moved to the original position.
but T(n) of your solution is O(k * length), so it will exceed time limitation in that test case.you should replace k = k % length with k

yes, it should have caused the TLE, since T(n) of your solution is O(k*n), when k is asymptotically to n, we get O(n2). It means it will cause TLE even for the case where
k is equal to n 1 , usual case.
In another way, your solution is not correct in this issue.
you should struggle to finger out the solution with T(n) = O(n).