Solution to Single Number II by LeetCode

18 Jul

Question: https://oj.leetcode.com/problems/single-number-ii/

Question Name: Single Number II

Follow Up: Every element appears N times except  one for M time (N !=  M):
If N > M:

  • If N % M == 0: use dictionary to count the appearance;
  • If N % M != 0: similar with our solution, but change “(bitsResult[index] % N) << index” to “((bitsResult[index] % N) << index) // M”.

If N < M:

  • If M % N == 0: use dictionary to count the appearance;
  • if M % N != 0: let M = M % N, jump to the case N > M.

2 Replies to “Solution to Single Number II by LeetCode

  1. Here is another solution for the prob from leetcode

    Analysis from this blog post : http://traceformula.blogspot.com/2015/08/single-number-ii-how-to-come-up-with.html 

Leave a Reply

Your email address will not be published. Required fields are marked *

Please put your code into a <pre>YOUR CODE</pre> section. Thanks and Happy Coding!