Here is the situation, I have to cast from int to long and back to int from long. I am wondering whether I can avoid this casting.
long temp = (long) i + nums[i]; // i + nums[i] could be bigger than Integer.MAX_VALUE
// i and nums[] both are int type.
int row = (int) (temp % 2);
int col = (int) (temp / 2);
Where row
and col
will be used to access an array later.
One change I could do for the row
statement,
int row = (i%2 + nums[i]%2) % 2;
But I don't have any time-efficient implementation to replace the col
statement so that I can avoid long casting for the first statement.