title: Find single element from a non-empty array of integers, every element appears twice except for one
body: <p>I need to find single element from a non-empty array of integers (every element appears twice except for one, I have to find the one). </p>
  
  <p>My code is not giving desired result for sample test case (2,2,1). It should ideally return 1 as result but it is returning Null instead. Can you help me understand the issue with it.</p>
  
  <pre><code>def singleNumber(self, nums):
      """
      :type nums: List[int]
      :rtype: int
      """
      nums.sort()
      for i in range(1,len(nums)-1):
          if i==len(nums)-1:
              if nums[i]!=nums[i-1]:
                  return nums[i]
          if nums[i]!=nums[i+1] and nums[i]!=nums[i-1]:
              return nums[i]
  </code></pre>