My LeetCode grinding. Trying to do a problem a day.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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]))