Last active
April 8, 2021 10:23
-
-
Save anbento0490/ba52902ddd1b4596b8135386f1d25481 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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