You get a list of integers, nums.
Return a new list with the square of every number above 0. A number's square is the number times itself.
Keep the squares in the order of their numbers in nums.
Leave out 0 and the negative numbers. If no number is above 0, return an empty list.
Example 1:
Input: nums = [3, -1, 0, 4] Output: [9, 16] Explanation: Only 3 and 4 are above 0. 3 times 3 is 9, and 4 times 4 is 16.
Example 2:
Input: nums = [-5, -2, 0] Output: [] Explanation: No number is above 0.
Example 3:
Input: nums = [1, 2, 3] Output: [1, 4, 9] Explanation: Every number is above 0, so every number is squared.
Constraints:
numsmay be empty.- Every number is between -1000 and 1000.
Free plan: 30 tutor messages. PRO is unlimited.
Saved
Ctrl + Enter to check
