
class Solution(object):
    def findDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        result = []
        i = 0
        while i < len(nums):
            if nums[i] != nums[nums[i]-1]:
                nums[nums[i]-1], nums[i] = nums[i], nums[nums[i]-1] 
            else:
                i += 1

        for i in xrange(len(nums)):
            if i != nums[i]-1:
                result.append(nums[i])
        return result


class Solution(object):
    def findDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        result = []
        i = 0
        while i < len(nums):
            if nums[i] != nums[nums[i]-1]:
                nums[nums[i]-1], nums[i] = nums[i], nums[nums[i]-1] 
            else:
                i += 1

        for i in xrange(len(nums)):
            if i != nums[i]-1:
                result.append(nums[i])
        return result


from collections import Counter


class Solution2(object):
    def findDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        return [elem for elem, count in Counter(nums).items() if count == 2]

Add alternative solution for 'Find all duplicates in an array'
Add alternative solution for 'Find all duplicates in an array'

  
  class Solution(object):
      def findDuplicates(self, nums):
          """
          :type nums: List[int]
          :rtype: List[int]
          """
          result = []
          i = 0
          while i < len(nums):
              if nums[i] != nums[nums[i]-1]:
                  nums[nums[i]-1], nums[i] = nums[i], nums[nums[i]-1] 
              else:
                  i += 1
  
          for i in xrange(len(nums)):
              if i != nums[i]-1:
                  result.append(nums[i])
          return result
  
+ 
+ from collections import Counter
+ 
+ 
+ class Solution2(object):
+     def findDuplicates(self, nums):
+         """
+         :type nums: List[int]
+         :rtype: List[int]
+         """
+         return [elem for elem, count in Counter(nums).items() if count == 2]
+ 
Add alternative solution for 'Find all duplicates in an array'
## Code Before:

class Solution(object):
    def findDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        result = []
        i = 0
        while i < len(nums):
            if nums[i] != nums[nums[i]-1]:
                nums[nums[i]-1], nums[i] = nums[i], nums[nums[i]-1] 
            else:
                i += 1

        for i in xrange(len(nums)):
            if i != nums[i]-1:
                result.append(nums[i])
        return result

## Instruction:
Add alternative solution for 'Find all duplicates in an array'
## Code After:

class Solution(object):
    def findDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        result = []
        i = 0
        while i < len(nums):
            if nums[i] != nums[nums[i]-1]:
                nums[nums[i]-1], nums[i] = nums[i], nums[nums[i]-1] 
            else:
                i += 1

        for i in xrange(len(nums)):
            if i != nums[i]-1:
                result.append(nums[i])
        return result


from collections import Counter


class Solution2(object):
    def findDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        return [elem for elem, count in Counter(nums).items() if count == 2]
