Why is my solution in java wrong?


  • 0
    J
    public class Solution {
        public void rotate(int[] nums, int k) {
            int len = nums.length;
            int count = 1;
            int cur = 0;
            while(count <= len){
                count ++;
                int dest = (cur + k) % len;
                int tmp = nums[dest];
                if(count == 1){
                    nums[dest] = nums[cur];
                }
                else{
                    nums[dest] = tmp;   
                }
                cur = dest;
            }
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.