My LeetCode grinding. Trying to do a problem a day.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.py 331B

1234567891011121314
  1. class Solution:
  2. def makeNegIfEven(self, n):
  3. if n % 2 == 0:
  4. return -n
  5. else:
  6. return n
  7. def sortArrayByParity(self, A):
  8. return sorted(A, key = self.makeNegIfEven)
  9. s = Solution()
  10. print("Expected: [6, 4, 2, 1, 3]")
  11. print("Got:", s.sortArrayByParity([1, 2, 3, 4, 6]))