Hey there! Today, let’s dive back into the world of LeetCode problems with Swift.
After successfully conquering the Two Sum problem, we’re geared up to take on the next challenge: Two Sum II.
To make things interesting, let’s explore this problem using a two pointers technique. Ready to tackle it together?
Problem We are given an array of numbers sorted in non-decreasing order (this means each element is greater or equal to the preceding one) and a target value.
Today, I’d like to present a small algorithmic problem and some solutions I have come up with.
The problem is as follows: Given a string, determine if the parentheses are balanced.
Balanced parentheses mean that for every ( found, there must be a corresponding ) to balance it.
Input and output It is guarantee that any given string will contain at least one parenthesis.
in: "(hello" out: false in: "(hello()world)()" out: true in: "hello()(())" out: true in: "()" out: true in: "(" out: false Solutions Using a Hash Table (Dictionary) Let’s try a simple approach using a hash table.
Let’s continue working with more LeetCode problems, this time focusing on an easy one.
We need to find if, in a given array, we can find two numbers such that they can be added up to a certain target value. We can be certain that there will be only one solution.
Solution Brute force As with other problems, one first approach would be to compare all possible combinations to find the two numbers that adds to the target.
Hello everyone, in this post I want to explore a solution to the Contains Duplicates LeetCode problem using Swift. Most solutions use Python and I think it would be a good idea to try to use Swift to explore how well it behaves for the LeetCode style questions.
The Problem This problem states that we have an array of integers and it may contain some values that are duplicated, so we need to write a function that check if the given array contains any element more than once.