Skip to content

Commit 5f6b1b5

Browse files
2460_Apply_Operations_to_an_Array.java
1 parent 9695373 commit 5f6b1b5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Problem Number: 2460
2+
3+
// Apply Operations to an Array
4+
5+
class Solution{
6+
public int[] applyOperations(int[] nums) {
7+
int ans[]= new int[nums.length];
8+
9+
for(int i=0; i+1<nums.length; i++{
10+
if(nums[i]==nums[i+1]){
11+
nums[i] *=2;
12+
nums[i+1]=0;
13+
}
14+
}
15+
16+
int i=0;
17+
for(final int num: nums){
18+
if(num>0){
19+
ans[i++]=num;
20+
}
21+
}
22+
return ans;
23+
}
24+
}

0 commit comments

Comments
 (0)