MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / applyOperations

Method applyOperations

ApplyOperationsToAnArray.java:2–20  ·  view source on GitHub ↗
(int[] nums)

Source from the content-addressed store, hash-verified

1class Solution {
2 public int[] applyOperations(int[] nums) {
3 int nz=0;
4 int n = nums.length;
5 for(int i=0;i<n;i++){
6 if(i < n-1 && nums[i]!=0 && nums[i]==nums[i+1]){
7 nums[i]*=2;
8 nums[i+1]=0;
9 }
10 if(nums[i]!=0){
11 if(i!=nz){
12 int temp = nums[i];
13 nums[i] = nums[nz];
14 nums[nz] = temp;
15 }
16 nz++;
17 }
18 }
19 return nums;
20 }
21}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected