MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / sum_of_three

Function sum_of_three

Python/ThreeNumbersSum.py:32–51  ·  view source on GitHub ↗
(arr, target=0)

Source from the content-addressed store, hash-verified

30"""
31
32def sum_of_three(arr, target=0) :
33 result = list()
34 arr.sort()
35
36 for i in range(len(arr)-2) :
37 left = i+1;right=len(arr)-1
38
39 while left < right :
40 current_sum = arr[i] + arr[left] + arr[right]
41 if current_sum == target :
42 result.append((arr[i], arr[left], arr[right]))
43 left+=1
44 right-=1
45 elif current_sum < target :
46 left += 1
47 elif current_sum > target :
48 right -= 1
49 else :
50 print("Dont with the loop")
51 return result
52
53if __name__ == '__main__' :
54 print(sum_of_three([3,5,-4,8,11,1,-1,6]))

Callers 1

ThreeNumbersSum.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected