Python 5-liner O(N)O(1) bit manipulation


  • 0
    class Solution(object):
        def findDuplicate(self, nums):
            flag = 0
            for num in nums:
                if flag & (1<<num):
                    return num
                flag |= 1<<num
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.