function - Why the final result varies? -
when returning function, following coding style not seem work -
return (int) minim(mid-l,r-mid) + (int) (mid+mid==n)?1:0;
but following code working fine -
int x = minim(mid-l,r-mid); int y = (mid+mid==n)?1:0; return x+y ;
mid, l, r, n integers.
can please me understand why?
you need add parentheses '+' takes precedence on ternary operator '?:'
return (int) minim(mid-l,r-mid) + ((int) (mid+mid==n)?1:0);
Comments
Post a Comment