6.29
class Solution:
def sortedSquares(self, nums: List[int]) -> List[int]:
a = map(lambda x: x ** 2, nums)
b = list(a)
b.sort()
return b
和
class Solution:
def sortedSquares(self, nums: List[int]) -> List[int]:
a = map(lambda x: x ** 2, nums)
b = list(a)
c = sorted(b)
return c
sort()是list的函数,只是在当前的地址更改顺序,sorted()是python的内置函数,可以在全局调用的
map的其他用法:
class Solution:
def sortedSquares(self, nums: List[int]) -> List[int]:
def func(x):
return x ** 2
a = map(func, nums)
b = list(a)
c = sorted(b)
return c