Question d’entretien chez Goldman Sachs

write a function to swap integers not using third int?

Réponses aux questions d'entretien

Utilisateur anonyme

21 mars 2011

I believe this can be solved with simple subtraction: A = A + B B = A - B A = A - B For example, if A = 10 and B = 24: A = 10 + 24 = 34 B = 34 - 24 = 10 A = 34 - 10 = 24

7

Utilisateur anonyme

19 mars 2011

IIRC, this can be done using three XOR operations: A = A xor B B = A xor B A = A xor B

1