Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧩 LeetCode Solutions in Java

A curated collection of my LeetCode solutions — written in Java, documented with the reasoning behind each one.

Java LeetCode License


📌 About this repository

This repo is my personal, growing archive of solved LeetCode problems, implemented in Java.

It's not just a dump of accepted submissions. For each problem I document the intuition, the approach, and the time/space complexity — because the goal isn't only to make the tests pass, it's to understand why a solution works and when it's the right tool.

I treat each problem as a rep in fundamentals: data structures, algorithms, and the trade-offs between them. Where a first solution passes but isn't optimal, I note it honestly and add the better approach — because a green checkmark tells you the output is correct, not that you solved the problem the right way.

What you'll find here:

  • ✅ Clean, readable Java implementations
  • 🧠 The thought process behind each solution, not just the code
  • ⏱️ Complexity analysis for every problem
  • 🏷️ Problems tagged by topic and difficulty for easy navigation

🗂️ Repository structure

Solutions are grouped by difficulty, and each problem lives in its own folder named by its LeetCode number and title:

leetcode-java/
├── src/
│   ├── easy/
│   │   ├── _0001_TwoSum/
│   │   │   ├── Solution.java
│   │   │   └── NOTES.md          # intuition, approach, complexity
│   │   └── _0704_BinarySearch/
│   │       ├── Solution.java
│   │       └── NOTES.md
│   ├── medium/
│   │   └── _0167_TwoSumII/
│   └── hard/
└── README.md

Each Solution.java contains the implementation; the accompanying NOTES.md explains the reasoning.


📖 How each solution is documented

Every problem follows the same structure, so the reasoning is consistent and easy to review:

/**
 * 704. Binary Search  —  https://leetcode.com/problems/binary-search/
 * Difficulty: Easy
 * Topics: Binary Search, Array
 *
 * Intuition:
 *   The array is sorted, so checking the middle element tells us which
 *   half the target must be in — letting us discard half the search
 *   space on every step instead of scanning linearly.
 *
 * Approach:
 *   Keep two bounds, left and right. Compare the middle value to the
 *   target and move the bound that keeps the target in range.
 *
 * Time:  O(log n)
 * Space: O(1)
 */
class Solution {
    public int search(int[] nums, int target) {
        int left = 0, right = nums.length - 1;

        while (left <= right) {
            int mid = left + (right - left) / 2;   // avoids integer overflow
            if (nums[mid] == target) {
                return mid;
            } else if (nums[mid] < target) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        return -1;
    }
}

📊 Solutions index

# Problem Difficulty Topics Solution
0001 Two Sum 🟢 Easy Array, Hash Table Java
0125 Valid Palindrome 🟢 Easy Two Pointers, String Java
0704 Binary Search 🟢 Easy Binary Search Java
0167 Two Sum II - Input Array Is Sorted 🟡 Medium Two Pointers, Binary Search Java

This table grows with every problem I solve. Difficulty legend: 🟢 Easy · 🟡 Medium · 🔴 Hard.


▶️ Running a solution locally

All you need is a JDK (17+ recommended).

# Clone the repo
git clone https://github.com/oazevedolucas/leetcode-java.git
cd leetcode-java

# Compile and run a specific solution
javac src/easy/_0704_BinarySearch/Solution.java
java -cp src/easy/_0704_BinarySearch Solution

Check your Java version with:

java -version

🏷️ Topics covered

As the collection grows, this section maps the algorithmic patterns practiced:

Array · Hash Table · Two Pointers · Binary Search · String · Sliding Window · Stack · Linked List · Trees · Dynamic Programming · Graphs


📈 Progress

Difficulty Solved
🟢 Easy
🟡 Medium
🔴 Hard
Total

Updated as I go. The number matters less than understanding each one.


🎯 Why I do this

I'm a backend engineer, and strong fundamentals are what let you reason about performance, choose the right data structure under pressure, and write code that scales. This repo is where I keep that muscle sharp — one problem at a time.


🔗 Let's connect

LinkedIn GitHub

Lucas Azevedo Souza — Senior Backend Engineer · Java · Spring Boot · Microservices · AWS

⭐ If you find any solution helpful, consider starring the repo!

About

My leetCodes in Java

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages