GithubHelp home page GithubHelp logo

vnaonlu / leetcode-daily Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 2.0 9.89 MB

a project including my leetcode solutions with unittests, which are written in c++.

License: MIT License

CMake 0.07% C++ 95.71% Python 4.22% Shell 0.01% Batchfile 0.01%
cpp cpp20 leetcode leetcode-solutions algorithms

leetcode-daily's Introduction

LeetCode Daily in C++

gccbuild msvcbuild

This repository collects some of my LeetCode solutions in C++ for free questions since 2021/09/06. The remain questions is still being solved so the current project may not contain the solutions you are looking for. Please check the chapter Getting Started for more details.

Here is my LeetCode account if you are interested.

Getting Started

See Activity to check the recent solution resolution status, including the historical statistics and the recent submissions. All solved solutions are stored in src and more information can be found at Find Solution. See Installation if you are interested in how to build the project or add some testcases for some solutions.

More information about solved solution can be found at docs/solved_solutions.md and unsolved questions can be found at docs/unsolved_solutions.md.

Activity

progress activity

More information about full activities can be found at:

Finding Solution

All solved solution information can be found at docs/solved_solutions.md and all solutions are in the directory of src corresponding to their LeetCode frontend ID. For instance, the solution for 1. Two Sum is stored in src/q_1_50/q0001.cc. In addition, the solution fragment always appear between LEETCODE_BEGIN_RESOLVING and LEETCODE_END_RESOLVING, e.g.

// ...
LEETCODE_BEGIN_RESOLVING(1, TwoSum, Solution);

class Solution {
public:
  vector<int> twoSum(vector<int> &nums, int target) {
    auto memo = unordered_map<int, int>();
    for (int i = 0; i < nums.size(); ++i) {
      auto find = memo.find(target - nums[i]);
      if (find != memo.end()) {
        return vector<int>{find->second, i};
      }
      memo.emplace(nums[i], i);
    }
    return vector<int>{-1, -1};
  }
};

LEETCODE_END_RESOLVING(Solution);
// ...

Or you can simply use the script ldt to cat the specific solution via:

# in the project root
$ ./ldt cat <question id>

But the script probably won't work as it is very rough currently.

Installation

It is not necessary to build or install this project if you just want to find specific solutions, but you can still build and run this project. There has a script named ldt in the root, which is a tool to automatically add/delete the solution in this project, generate the solution template or update the readme or log. However the script may too rough to use since I haven't tested it in other environment.

Before running to build project, please check below dependencies:

  • C++20 supported Compiler.
  • CMake above 3.20.

Then you can build the project manually by

$ git clone https://github.com/vNaonLu/leetcode-daily.git
$ cd leetcode-daily
$ cmake -S . -B build -DENABLE_LEETCODE_TEST=ON
$ cmake --build build
# Run the unittests
$ ./build/leetcode_test

leetcode-daily's People

Contributors

vnaonlu avatar

Stargazers

AnnTsai avatar  avatar

Watchers

 avatar

leetcode-daily's Issues

Wrong unit test template generated when the type of solution function is void.

Found issue when adding question #130

template generated by leetcode_add.py:

// since the solution function with void return type
void solve(vector<vector<char>>& board) {}

// then the pytool generates an ambiguous variable.
void exp = [["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]];

Wrong argument type generated

Found the issue with Question #174

//actual
  vector<int> dungeon = {-2, -3, 3, -5, -10, 1, 10, 30, -5};

//expect
  vector<vector<int>> dungeon = {{-2, -3, 3}, {-5, -10, 1}, {10, 30, -5}};

LDT: merge message.

A merged message from devel/daily to main is need.
I am considering the following format:


adds the {count} solution(s) in week{week}.
add solutions details:
  * {rev} adds q{id} with TC O({tc}) and SC O({sc}).
  * {rev} adds q{id}.
  * {rev} adds q{id} with TC O({tc}) and SC O({sc}) where {note}.

The string in test cases is not define if the value is "".

Found the issue in Question #17

TEST(q17, sample_input02) {
  l17::Solution solver;
  // miss this-> string digits = "";
  vector<string> exp = {};
  // Try EXPECT_EQ_ANY_ORDER_RECURSIVE
  // if the element is also matched in any order.
  EXPECT_EQ_ANY_ORDER(solver.letterCombinations(digits), exp);
}

Wrong test case parsing with question 463

TEST(q463, sample_input01) {
  l463::Solution solver;
  vector<vector<int>> grid = {};
  //0 = 0
  //1 = 1
  //1 = 0
  //0 = 1
  //0 = 0
  //1 = 1
  //0 = 0
  int exp = 16;
  EXPECT_EQ(solver.islandPerimeter(grid), exp);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.