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

Update ✅ Pattern 02: Two Pointers.md #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dev-arminder wants to merge 1 commit into Chanda-Abdul:main from dev-arminder:patch-2
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions ✅ Pattern 02: Two Pointers.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,6 @@ To follow a similar approach, first, we will sort the array and then iterate thr
Another difference from [Pair with Target Sum](#🌴-pair-with-target-sum-aka-"two-sum"-easy) is that we need to find all the unique triplets. To handle this, we have to skip any duplicate number. Since we will be sorting the array, so all the duplicate numbers will be next to each other and are easier to skip.

````js
function searchTriplets(arr) {
arr.sort((a, b) => a-b)
const triplets = [];

for(i = 0; i< arr.length;i++) {

if(i>0 && arr[i] === arr[i -1]){
//skip the same element to avoid dupes
continue
}
searchPair(arr, -arr[i], i+1, triplets)
}
return triplets;
};

function searchTriplets(arr) {
arr.sort((a, b) => a -b)
const triplets = []
Expand Down

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