You are viewing a single comment's thread. Return to all comments →
Great solution ajaycarnet. I compared yours with my own and yours is much faster.
var sw = Stopwatch.StartNew(); int[] array = new int[n]; for(int i = 0; i < n; i++) array[(i + (n - d)) % n] = int.Parse(s[i]); sw.Stop(); for(int i = 0; i < n; i++) Console.Write(array[i] + " "); Console.WriteLine(); Console.WriteLine(sw.ElapsedTicks); // 5 ticks sw = Stopwatch.StartNew(); int[] a1 = Array.ConvertAll(s, Int32.Parse); int[] buffer = new int[d]; Array.Copy(a1, 0, buffer, 0, d); Array.Copy(a1, d, a1, 0, a1.Length - d); Array.Copy(buffer, 0, a1, a1.Length - d, d); sw.Stop(); foreach(var num in a1) Console.Write(num + " "); Console.WriteLine(); Console.WriteLine(sw.ElapsedTicks); // 700+ ticks
Seems like cookies are disabled on this browser, please enable them to open this website
Left Rotation
You are viewing a single comment's thread. Return to all comments →
Great solution ajaycarnet. I compared yours with my own and yours is much faster.