A collection of Java solutions to LeetCode problems, organized by difficulty, with JUnit tests for each solution.
Easy/ β Solutions for Easy problems
Medium/ β Solutions for Medium problems
Hard/ β Solutions for Hard problems
tests/ β JUnit test files for each solution
lib/ β JUnit and Hamcrest libraries
- Compile solution and test files (from project root):
javac -cp ".;lib/*" Easy/YourSolution.java tests/Easy/YourSolutionTest.java
- Run the JUnit tests:
java -cp ".;lib/*" org.junit.runner.JUnitCore tests.Easy.YourSolutionTest
Replace
YourSolution
andYourSolutionTest
with the actual file/class names.
For the first problem, IntersectionOfTwoArraysII
:
Compile:
javac -cp ".;lib/*" Easy/IntersectionOfTwoArraysII.java tests/Easy/IntersectionOfTwoArraysIITest.java
Run Test:
java -cp ".;lib/*" org.junit.runner.JUnitCore tests.Easy.IntersectionOfTwoArraysIITest
All tests should pass if the solution is correct.
- Add new solutions under the appropriate difficulty folder (
Easy/
,Medium/
,Hard/
). - Add a matching JUnit test under
tests/
with the same package structure. - Commit and push your changes to keep the repo updated.
- Each solution should be self-contained with proper class and method names.
- Tests use JUnit 4. Make sure
lib/junit-4.13.2.jar
andlib/hamcrest-core-1.3.jar
are present. - Keep naming consistent for readability and maintainability.
Happy coding! π