双指针做法,第一句是黑科技
class Solution:def twoSum(self, nums: List[int], target: int) -> List[int]:# 黑科技ids = sorted(range(len(nums)), key=lambda x: nums[x])nums.sort()l, r = 0, len(nums)-1while True:sum0 = nums[l] + nums[r]if sum0 == target:return [ids[l], ids[r]]elif sum0 < target:l += 1else:r -= 1