Skip to content

A modern C++ framework for LeetCode practice with automated problem generation, integrated testing, and solution management.

License

Notifications You must be signed in to change notification settings

T3mps/LeetPlusPlus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LeetPlusPlus

LPP CLI A

A professional C++ development framework for LeetCode problem solving, featuring an interactive CLI, automated problem fetching, integrated testing, and a native terminal interface.

πŸš€ Quick Start

# Enter interactive console
lpp

# Or use direct commands
lpp fetch 1            # Fetch Two Sum
lpp list               # Show all problems
lpp update             # Update problem metadata

✨ Key Features

Automated Problem Management

  • Fetch by Number: fetch 1 - Two Sum
  • Fetch by Slug: fetch two-sum
  • Daily Challenge: fetch daily
  • Random Problems: random medium
  • Smart Filtering: list --difficulty easy --limit 10

Professional Code Generation

  • Automatic C++ template generation with proper includes
  • Smart type conversion (LeetCode β†’ C++)
  • Integrated test case parsing
  • Company and topic tag tracking

Native Terminal UI

  • 🟒 Easy problems in green
  • 🟑 Medium problems in yellow
  • πŸ”΄ Hard problems in red
  • Navigate with arrow keys
  • Execute problems with Enter

πŸ“‹ Prerequisites

  • C++ Compiler: C++17 compatible (MSVC 2019+, GCC 7+, Clang 5+)
  • Build System: Premake5
  • Python: 3.6+ with pip
  • Node.js: For LeetCode API (auto-managed)
  • Git: For cloning the repository

πŸ› οΈ Installation

1. Clone the Repository

git clone --recursive https://github.com/yourusername/LeetPlusPlus.git
cd LeetPlusPlus

2. Install Python Dependencies

pip install -r requirements.txt

3. Build the Project

# Windows (Visual Studio 2022)
premake5 vs2022

# Linux/macOS
premake5 gmake2
make

# Xcode
premake5 xcode4

4. First Run

# Enter the console
lpp

# Update problem metadata (first time)
β–Ά update

🎯 Usage Guide

Console Commands

Command Description Example
fetch <id|slug> Fetch a problem fetch 1 or fetch two-sum
list List all problems list --difficulty easy
update Update problem metadata update
generate <id> Generate solution file generate 42
random [difficulty] Fetch random problem random medium
status Show system status status
help Show help help fetch
clear Clear screen clear
exit Exit console exit

Writing Solutions

Generated problems follow this structure:

#pragma once
#include "../Base/TestUtils.h"
#include <vector>

class Solution1 {
public:
    std::vector<int> TwoSum(std::vector<int>& nums, int target) {
        // Your solution here
        return {};
    }
};

void TestSolution1() {
    Solution1 solution;
    TestRunner runner("1. Two Sum");
    
    // Test cases are auto-generated
    runner.addTest({1, 2, 3}, 4, {0, 2});
    runner.addTest({2, 7, 11, 15}, 9, {0, 1});
    
    runner.run([&](auto& nums, auto target) {
        return solution.TwoSum(nums, target);
    });
}

Testing Framework

The framework provides comprehensive testing utilities:

// Assertion macros
ASSERT_EQ(actual, expected)           // Basic equality
ASSERT_VECTOR_EQ(vec1, vec2)          // Vector comparison
ASSERT_TREE_EQ(tree1, tree2)          // Tree structure comparison
ASSERT_LINKED_LIST_EQ(list1, list2)   // Linked list comparison

// Test organization
TEST_CASE("Edge case description")
TestRunner::PrintSummary()

LeetPlusPlus Terminal Interface A LeetPlusPlus Terminal Interface B

πŸ”§ Configuration

Project Structure

LeetPlusPlus/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ Problems/        # Generated problem solutions
β”‚   β”œβ”€β”€ Base/           # Core framework code
β”‚   β”œβ”€β”€ Common/         # Shared utilities
β”‚   └── UI/             # Terminal interface
β”œβ”€β”€ tools/              # Python CLI and utilities
β”œβ”€β”€ vendor/             # Third-party dependencies
└── lpp.py             # Main CLI entry point

API Configuration

The AlfaLeetCode API server is managed automatically. If needed, you can configure:

  • API URL: Default http://localhost:3000
  • Auto-start: Enabled by default
  • Manual start: cd vendor/AlfaLeetCode && npm start

πŸ› Troubleshooting

Common Issues

"No metadata found"

lpp update  # Fetches problem list from LeetCode

"API server not running"

  • The server should auto-start
  • Check if port 3000 is available
  • Try manual start: cd vendor/AlfaLeetCode && npm install && npm start

"Problem already exists"

lpp fetch 1 --force  # Overwrite existing solution

Build Issues

  • Ensure Premake5 is in your PATH
  • Check compiler compatibility (C++17 required)
  • On Windows, use "x64" configuration in Visual Studio

🀝 Contributing

Contributions are welcome! Please ensure:

  • Code follows existing style conventions
  • Documentation is updated
  • Commit messages are descriptive

πŸ“„ License

This project is licensed under the MIT License. See LICENSE file for details.

πŸ™ Acknowledgments


Note: This project is not affiliated with LeetCode. It's an independent tool to enhance the LeetCode problem-solving experience for C++ developers.

About

A modern C++ framework for LeetCode practice with automated problem generation, integrated testing, and solution management.

Topics

Resources

License

Stars

Watchers

Forks