不重复打印三元组_python3
不重复打印排序数组中相加和为给定值的所有三元组
http://www.nowcoder.com/questionTerminal/11b7dd7cbf064900bc664bb5fd4e2fab
数据竟然不允许前两个数相同,要加上and l[i] != l[a]。。。
n, k = map(int, input().split()) l = list(map(int, input().split())) for i in range(n - 2): if i > 0 and l[i] == l[i-1]: continue x = k - l[i] a = i + 1 b = n - 1 while a < b: tmp = l[a] + l[b] if tmp == x and l[i] != l[a]: print(l[i], l[a], l[b]) a += 1 b -= 1 while l[a] == l[a-1] and a < b: a += 1 while l[b] == l[b+1] and a < b: b -= 1 elif tmp < x: a += 1 else: b -= 1