Lädt...

🔧 Leetcode - 15. 3Sum


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Javascript Code

/**
 * @param {number[]} nums
 * @return {number[][]}
 */
var threeSum = function (nums) {
    let res = [];
    nums.sort((a, b) => a - b);
    for (let i = 0; i < nums.length; i++) {
        if (i > 0 && nums[i - 1] == nums[i]) {
            continue;
        }
        let p1 = i + 1;
        let p2 = nums.length - 1;
        while (p1 < p2) {
            let threesum = nums[p1] + nums[p2] + nums[i];
            if (threesum > 0) {
                p2--;
            } else if (threesum < 0) {
                p1++;
            } else {
                res.push([nums[i], nums[p1], nums[p2]]);
                p1++;
                while (p1 < p2 && nums[p1 - 1] == nums[p1]) {
                    p1++;
                }
            }
        }
    }

    return res;

};
...

🔧 Leetcode - 15. 3Sum


📈 43.67 Punkte
🔧 Programmierung

🔧 LeetCode Challenge: 15. 3Sum - JavaScript Solution 🚀


📈 43.67 Punkte
🔧 Programmierung

🔧 Array- Q4 3Sum


📈 31.27 Punkte
🔧 Programmierung

🔧 3Sum - Print unique Pairs


📈 31.27 Punkte
🔧 Programmierung

🔧 Automating Your LeetCode Journey: Building an Enterprise-Grade LeetCode to GitHub Sync System


📈 24.8 Punkte
🔧 Programmierung

🔧 Cracking Stack and Queue LeetCode Problems: A Step-by-Step Guide to Solving LeetCode Challenges


📈 24.8 Punkte
🔧 Programmierung

🔧 I built an AI powered coding interviewer to practice LeetCode


📈 12.4 Punkte
🔧 Programmierung

🔧 Leetcode - 150. Evaluate Reverse Polish Notation


📈 12.4 Punkte
🔧 Programmierung

🔧 Leetcode - 6. Zigzag Conversion


📈 12.4 Punkte
🔧 Programmierung

🔧 Leetcode — 3146. Permutation Difference between Two Strings


📈 12.4 Punkte
🔧 Programmierung

🔧 LeetCode Meditations: Sum of Two Integers


📈 12.4 Punkte
🔧 Programmierung

🔧 LeetCode Meditations — Chapter 14: Bit Manipulation


📈 12.4 Punkte
🔧 Programmierung

🔧 My LeetCode Journey: From Beginner to Earning the Annual Badge!


📈 12.4 Punkte
🔧 Programmierung

🔧 The Struggle of Passing Coding Tests: LeetCode and Algorithm Mastery


📈 12.4 Punkte
🔧 Programmierung

🔧 Leetcode: 1768. Merge Strings Alternately


📈 12.4 Punkte
🔧 Programmierung

🔧 Day 3| Linked List: leetcode 203,706,206 in Cpp


📈 12.4 Punkte
🔧 Programmierung

🔧 LeetCode Day21 BackTracking Part 3


📈 12.4 Punkte
🔧 Programmierung

🔧 LeetCode Day5 HashTable


📈 12.4 Punkte
🔧 Programmierung

🔧 How to Determine if an Integer is a Palindrome on LeetCode


📈 12.4 Punkte
🔧 Programmierung

🔧 Path Sum | LeetCode | Java


📈 12.4 Punkte
🔧 Programmierung

🔧 LeetCode - Divide Two Integers


📈 12.4 Punkte
🔧 Programmierung

🔧 Leetcode - 206. Reverse Linked List


📈 12.4 Punkte
🔧 Programmierung

🔧 Leetcode - 48. Rotate Image


📈 12.4 Punkte
🔧 Programmierung

🔧 Unofficial LeetCode API + Daily Updated Google Sheet


📈 12.4 Punkte
🔧 Programmierung

🔧 LeetCode Challenge: 76. Minimum Window Substring - JavaScript Solution 🚀


📈 12.4 Punkte
🔧 Programmierung

🔧 Breaking Into Problem Solving: My LeetCode Journey


📈 12.4 Punkte
🔧 Programmierung

🔧 LeetCode Meditations: Merge Intervals


📈 12.4 Punkte
🔧 Programmierung

🔧 Two Sum Problem’ on LeetCode


📈 12.4 Punkte
🔧 Programmierung

🔧 Leetcode 678 :- Valid Parenthesis String


📈 12.4 Punkte
🔧 Programmierung

🔧 Top 4 Must-Have Browser Extensions for LeetCode Enthusiasts


📈 12.4 Punkte
🔧 Programmierung

🔧 LeetCode Meditations: House Robber II


📈 12.4 Punkte
🔧 Programmierung

🔧 LeetCode Day 13 Binary Tree Part 4


📈 12.4 Punkte
🔧 Programmierung

🔧 Valid Parentheses | LeetCode | Java


📈 12.4 Punkte
🔧 Programmierung

🔧 Solving a Leetcode problem daily - Day 1 | Pascal’s Triangle


📈 12.4 Punkte
🔧 Programmierung

🔧 LeetCode 2634. Filter Elements from Array (Easy)


📈 12.4 Punkte
🔧 Programmierung

matomo