-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex.java
More file actions
41 lines (40 loc) · 1022 Bytes
/
ex.java
File metadata and controls
41 lines (40 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public class ex {
public void rotate(int[] nums, int k) {
int[] temp = new int[nums.length];
for(int i = 0;i<nums.length;i++){
temp[i] = nums[i];
}
int n =0;
for(int i =0;i<nums.length;i++){
if(nums.length%2 == 0){
if(i+k <nums.length){
nums[i] = temp[i+k];
n = i;
}
}
if(nums.length%2 !=0){
if(i+k<nums.length-1){
nums[i] = temp[i+k+1];
n=i;
}
}
}
int j =0;
if(n!=0){
for(int i = n+1;i<nums.length;i++){
if(j<=k){
nums[i] = temp[j];
j++;
}
}
}
else{
for(int i = n;i<nums.length;i++){
if(j<=k){
nums[i] = temp[j];
j++;
}
}
}
}
}