6gDav LeetCode Sulotions

Welcome to my LeetCode solutions collection!

Description

This is a collection page for my LeetCode solutions.
I created this because GitHub’s landing page lacks a "pinning" option (for all my repos),
and I wanted a place to organize my code.
I mainly solve LeetCode problems for practice and to learn complex algorithms, rather than for job interviews.


Choose a LeetCode:

LeetCode 1.

Two Sum

Programing langeuge: Rust 🦀

My sulotions ☺️


🧠 How I solved the problem

I implemented a brute-force solution using nested loops.
To avoid the "double-counting" bug (using the same element twice),
the inner loop starts from the next element relative to the outer loop.
This ensures that we only compare distinct pairs and find the target sum
without using any element more than once.


LeetCode 2.

Add Two Numbers x ➕ ⅹ

Programing langeuge: Rust 🦀

My sulotions ☺️


🧠 How I solved the problem

I reversed both input lists, then iterated through the elements and
converted them to strings. After concatenating them, I parsed the final
string back into an i32 to get the full number.
I did this for both lists, added the two numbers together,
and finally converted the sum back to a reversed list of characters.


LeetCode 4.

Median of Two Sorted Arrays 🖖

Programing langeuge: Rust 🦀

My sulotions ☺️


🧠 How I solved the problem

First, I concatenated and sorted the given lists.
Then, I implemented the following logic: if the combined list length is even,
I split it in the middle and calculate the average of the two central elements.
If the length is odd, I simply return the middle element.


LeetCode 5.

Longest Palindromic Substring 🤥

Programming language: Rust 🦀

My solutions ☺️


🧠 How I solved the problem

First, I return the original string if it is equal to its reversed version to avoid unnecessary processing. After this, I implemented a for loop that continuously compares a new string with its own reversed version. The backward logic follows the same principle. The last one is a bit of a silly attempt, but I'll leave it in.


LeetCode 54.

Spiral Matrix

Programming language: Rust 🦀

My solutions ☺️


🧠 How I solved the problem

I created a while loop that runs until the matrix becomes empty or the first row runs out. In the while loop I implemented four steps: 1. remove the current first row and add it to the solution vector 2. iterate through all rows and remove all last elements while pushing these to the vector 3. remove the entire last row reverse it and add it too to the solution 4. add every first element while remove these too As you see my solution based on remove and cloning.


LeetCode 6.

Zigzag Conversion

Programming language: Rust 🦀

My solutions ☺️


🧠 How I solved the problem

First, I implemented an early return for cases with only a single character. Then, I created an array of strings (acting as a matrix) based on the number of rows. I iterated through the input, pushing each character into the appropriate row index. The logic relies on the 'step' variable that increments or decrements the 'current_row' index. This 'step' changes whenever we reach the top or bottom row, determining where the next character is placed.


LeetCode 4.2.

Median of Two Sorted Arrays 🖖

Programming language: Dart 🎯

My solutions ☺️


🧠 How I solved the problem

First, I concatenated and sorted the given lists. Then, I implemented the following logic: if the combined list length is even, I split it in the middle and calculate the average of the two central elements. If the length is odd, I simply return the middle element.


LeetCode 7.

Reverse Integer 🔄

Programming language: Rust 🦀

My solutions ☺️


🧠 How I solved the problem

I implemented an if-else expression with two branches. In the first case, if the input is negative, I take its absolute value, convert it to a string, reverse it, and return it to the variable. The else block does the same but without the absolute value. Finally, I parsed the resulting string back into an integer.


LeetCode 9.

Palindrome Number 6️⃣7️⃣

Programming language: Rust 🦀

My solutions ☺️


🧠 How I solved the problem

I implemented a string-based solution. First, I converted the number to a string for easier handling. After this, I used an early return to return true if the string is only one character long. Finally, I return a boolean based on whether the string matches its reversed version.