Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b44e7cd

Browse files
committed
two pointer - pair target sum
1 parent 6a89f08 commit b44e7cd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

‎Two pointer/pair_with_target_sum.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
arr = [1, 2, 3, 4, 6]
2+
target = 6
3+
left, right = 0, len(arr) - 1
4+
result = []
5+
while left < right:
6+
print(f"left: {arr[left]}, right: {arr[right]}")
7+
if arr[left] + arr[right] == target:
8+
result = [left, right]
9+
break
10+
elif arr[left] + arr[right] > target:
11+
right -= 1
12+
else:
13+
left += 1
14+
print(result)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /