forked from mirandaio/codingbat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtenRun.java
More file actions
27 lines (22 loc) · 746 Bytes
/
tenRun.java
File metadata and controls
27 lines (22 loc) · 746 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
/* For each multiple of 10 in the given array, change all the values
* following it to be that multiple of 10, until encountering another
* multiple of 10. So {2, 10, 3, 4, 20, 5} yields {2, 10, 10, 10, 20, 20}.
*/
public int[] tenRun(int[] nums) {
int current;
int i = 0;
while(i < nums.length && nums[i] % 10 != 0)
i++;
if(i >= nums.length)
return nums;
current = nums[i];
i++;
while(i < nums.length) {
if(nums[i] % 10 == 0)
current = nums[i];
else
nums[i] = current;
i++;
}
return nums;
}