Given an array of integers, rotate the array by 'N' elements.

Descrição

FlashCards sobre Given an array of integers, rotate the array by 'N' elements., criado por Suhas S em 12-02-2018.
Suhas S
FlashCards por Suhas S, atualizado more than 1 year ago
Suhas S
Criado por Suhas S mais de 6 anos atrás
0
0

Resumo de Recurso

Questão Responda
Given an array of integers, rotate the array by 'N' elements. class Solution { public void rotate(int[] nums, int k) { k = k%nums.length; reverse(nums, 0 , nums.length -1); reverse(nums, 0 , k - 1); reverse(nums, k , nums.length -1 ); } public void reverse(int[] nums,int start,int end){ while( start < end){ int temp = nums[start]; nums[start] = nums[end]; nums[end] = temp; start++; end--; } } }

Semelhante

PHP Exam One
tr.badhan
Array Programs
Subash M
Array
alim586
Array
Tate Johnson
Test Card
Nick Wu
Single sell stock
Suhas S
Remove Duplicates from Sorted Array
Suhas S
10 Dicas para lidar com conflitos no ambiente de trabalho
Liliane Tubino
LICITAÇÕES (visão geral)
Priscila Franco Andrade
Exercícios de fixação – Informática Básica
Renato Costa