Title: Three Sum in Python - Runnable Code Snippet
Open Graph Title: Three Sum in Python - Runnable Code Snippet
X Title: Three Sum in Python - Runnable Code Snippet
Description: Find all unique triplets in an array that sum to a target value. Runnable Python snippet with live execution.
Open Graph Description: Find all unique triplets in an array that sum to a target value. Runnable Python snippet with live execution.
X Description: Find all unique triplets in an array that sum to a target value. Runnable Python snippet with live execution.
Keywords:
Opengraph URL: https://tempercode.dev/snippets/three-sum-python
Domain: tempercode.dev
{"@context":"https://schema.org","@type":"SoftwareSourceCode","name":"Three Sum","description":"Find all unique triplets in an array that sum to a target value.","programmingLanguage":"Python","text":"a = sorted(arr)\nresult = []\nfor i in range(len(a) - 2):\n if i > 0 and a[i] == a[i - 1]:\n continue\n l, r = i + 1, len(a) - 1\n while l < r:\n s = a[i] + a[l] + a[r]\n if s == target:\n result.append([a[i], a[l], a[r]])\n while l < r and a[l] == a[l + 1]: l += 1\n while l < r and a[r] == a[r - 1]: r -= 1\n l += 1; r -= 1\n elif s < target: l += 1\n else: r -= 1\nresult"}
| theme-color | #0c0d12 |
| color-scheme | dark |
| author | Temper |
| creator | Temper |
| publisher | Temper |
| og:image | https://tempercode.dev/og-image.png |
| og:type | article |
| twitter:card | summary_large_image |
| twitter:image | https://tempercode.dev/og-image.png |
Links:
Viewport: width=device-width, initial-scale=1