728x90
반응형
1. Link to the problem
2. Point
- Use memory
3. Source
public class ArraysLeftRotation
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int a[] = new int[n];
for (int a_i = 0; a_i < n; a_i++)
{
a[a_i] = in.nextInt();
}
int res[] = solve(a, n, k);
for (int i = 0; i < res.length; i++)
System.out.print(res[i] + " ");
}
public static int[] solve(int a[], int n, int k)
{
int res[] = new int[n];
int index;
for (int i = 0; i < n; i++)
{
index = i - k;
if (index < 0)
index = index + n;
res[index] = a[i];
}
return res;
}
}
'algorithm > hackerRank' 카테고리의 다른 글
[HackkerRank] Hash Tables: Ice Cream Parlor (0) | 2018.06.25 |
---|---|
[HackkerRank] Bit Manipulation: Lonely Integer (0) | 2018.06.25 |
HackkerRank: Time Complexity:Primality (0) | 2018.06.23 |
HackerRank BFS: Shortest Reach in a Graph (0) | 2018.03.09 |
HackerRank DFS: Connected Cell in a Grid (java) (0) | 2018.03.08 |
댓글