1.我的思路枚举利用嵌套循环解决问题但是这个效率低水平低。没有含金量主要语法abs( x )函数返回 x数字的绝对值如果参数是一个复数则返回它的大小。list.append(obj)class Solution(object): def countGoodTriplets(self, arr, a, b, c): :type arr: List[int] :type a: int :type b: int :type c: int :rtype: int list[] for i in range(0,len(arr)-2): for j in range(i1,len(arr)-1): for k in range(j1,len(arr)): if abs(arr[i] - arr[j]) a and abs(arr[j] - arr[k]) b and abs(arr[i] - arr[k]) c: list.append([arr[i],arr[j],arr[k]]) return len(list)2.根据官方也容易想到的思路双重循环优化先进行两重循环的判断在进行综合验证class Solution(object): def countGoodTriplets(self, arr, a, b, c): :type arr: List[int] :type a: int :type b: int :type c: int :rtype: int list[] for i in range(0,len(arr)-2): for j in range(i1,len(arr)-1): if abs(arr[i] - arr[j]) a: continue for k in range(j1,len(arr)): if abs(arr[j] - arr[k]) b and abs(arr[i] - arr[k]) c: list.append([arr[i],arr[j],arr[k]]) return len(list)