Skip to content

Instantly share code, notes, and snippets.

@anbento0490
Last active April 8, 2021 10:23
Show Gist options
  • Save anbento0490/ba52902ddd1b4596b8135386f1d25481 to your computer and use it in GitHub Desktop.
Save anbento0490/ba52902ddd1b4596b8135386f1d25481 to your computer and use it in GitHub Desktop.
#Example
# Input: nums = [-6, 1, 0, 3, 18]
# Output: [-1, 0, 9, 36, 324]
# Explanation: Only -6, 3 and 18 are divisible by 3 and will be squared.
# After squaring and sorting the list, it becomes [-1, 0, 9, 36, 324]
nums = [-6,-1,0,3,8,12]
def solution(nums):
return sorted([nums[i]**2 if nums[i]%3 ==0 else nums[i] for i in range(len(nums))])
solution(nums)
#Output: [-1, 0, 8, 9, 36, 144]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment