题目描述
题目链接:https://leetcode-cn.com/problems/decompress-run-length-encoded-list/
解题思路
双指针
AC代码如下:
class Solution:
def twoSum(self, numbers: List[int], target: int) -> List[int]:
# 索引从1开始,不妨首位补零
numbers = [0] + numbers
# 定义双指针
i,j = 1,len(numbers)-1
# ======== 双指针 惯用写法 =============
while (i<j):
if numbers[i]+numbers[j]<target:
i += 1
elif numbers[i]+numbers[j]>target:
j -= 1
else:
break
# ===========================
return [i,j]