The title

Design an algorithm to find the smallest k number in an array. You can return these k numbers in any order.

Example:

Input: arr =,3,5,7,2,4,6,8 [1], k = 4 output: [1, 2, 3, 4] tip:Copy the code

0 <= len(arr) <= 100000 0 <= k <= min(100000, len(arr))

Their thinking

class Solution: def smallestK(self, arr: List[int], k: int) -> List[int]: arr.sort() return arr[:k] if __name__ == '__main__': Arr = [1,3,5,7,2,4,6,8] k = 2 Solution(). Print (ret)Copy the code