PHP 52 ms, faster than 90.00%
class Solution {

    /**
     * @param Integer[] $nums
     * @param Integer $k
     * @return NULL
     */
    function rotate(&$nums, $k) {
        
        $l= count($nums)-1;
        $k %= $l+1;
       $nums= $this->reverse($nums, 0, $l);
       $nums= $this->reverse($nums, 0, $k-1);        
       $nums= $this->reverse($nums, $k, $l);      
   
    }
    function reverse($nums, $first, $last){
        while($first<$last){
        $new = $nums[$first];
        $nums[$first]=$nums[$last];
        $nums[$last]= $new;  
            $first++;
            $last--;
        }
       return $nums;
        

    }
}

Please upvote if you like the solution and feel free to ask for more information if you need-

Comments (1)