Failing the test case [1,2] k = 3. Can anyone tell why?


  • 0
    P

    public class Solution {
    public void rotate(int[] nums, int k) {
    if(nums == null)
    return;

    	int len = nums.length;
    	
    	if (k >= len)
    		return;
    	
    	int i = 0, j = 0, index = 0;
    	
    	if (k > len)
    	 k = k % len;
    	 
    	for (i = len - k; i < len; i++) {
    		
    		j = i;
    		int temp = nums[i];
    		
    		while (j > index) {
    			nums[j] = nums[j - 1];
    			j--;
    		}
    		
    		nums[index++] = temp;
    	}
    }
    

    }


  • 0
    J

    if k >= len return ....


Log in to reply
 

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