You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// In a sorted collection, replaces the given index with a predecessor that maps to a unique element.
@@ -64,15 +64,15 @@ extension BidirectionalCollection where Element: Equatable {
64
64
65
65
You'll keep track of 3 indices to represent the 3 numbers. The sum at any given moment is `array[l] + array[m] + array[r]`:
66
66
67
-
```
67
+
```swift
68
68
m -><- r
69
69
[-4, -1, -1, 0, 1, 2]
70
70
l
71
71
```
72
72
73
73
The premise is quite straightforward (given that you're familiar with 2Sum). You'll iterate `l` through the array. For every iteration, you also apply the 2Sum algorithm to elements after `l`. You'll check the sum every time you moving the indices to check if you found match. Here's the algorithm:
0 commit comments