Manipulation Solutions
Manipulation Solutions
Solution 2: The idea is to use XOR operators to swap two numbers by their propertyx
^x=0
public class Solution {
public static void main(String[] args) {
int x = 3, y = 4;
Solution 3 : The expression -~x will add 1 to an integer x. We know that to get negative of a
number, invert its bits and add 1 to it (Remember negative numbers are stored in 2’s
complement form), i.e.,
-x = ~x + 1;
-~x = x + 1 (by replacing x by ~x)
https://telegram.me/+QGUyTripaP4zNTcx
https://telegram.me/+nEKeBr_yhXtmY2Yx
#TGSFamily