0

is there anyway to improve my code's time complexity or memory's complexity ? (without using advanced methods - im a beginner)

its a method that gets an array filled with zeroes and other numbers, and it changes each number(which is not a zero) to the distance of the closest zero to it.

for example this array: { 1 , 0 , 2 , 5 , 1 , 3 , 0 , 1 , 1 , 0 }

will be changed into this: {1 , 0 , 1 , 2 , 2 , 1 , 0 , 1 , 1 , 0}

```
for (int i=0; i<a.length; i++)
{
if (a[i]!=0){
int right=0, left=0;
for (int j=i; j>=0; j--) //count zeroes from the left side
{
if (a[j]!=0)
++left;
else
break;
}
for (int k=i; k<a.length; k++) //count zeroes from right side
if (a[k]!=0)
++right;
else
break;
a[i]=Math.min(right,left); //finds the closest zero
}
else
continue;
}
```