Cracking the coding interview Q19-20 | chaozh.com
19.1 Write a function to swap a number in place without temporary variables
x=x^y y=x^y x=x^y
19.2 Design an algorithm to figure out if someone has won in a game of tic-tac-toe
We could use 1 for player1 and 2 for player2 and sum caculation to judge if any player wins or we can simply go though all directions to judge after any player make a move.
19.3 Write an algorithm which computes the number of trailing zeros in n factorial
Just caculate how many 5 are there in factors as 2 is usualy enough and be careful that 25 has two 5 rather than one.
Read full article from Cracking the coding interview Q19-20 | chaozh.com
No comments:
Post a Comment