Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/beakerandjake/leetcode
My leetcode solution repository
https://github.com/beakerandjake/leetcode
leetcode leetcode-javascript leetcode-solutions
Last synced: 7 days ago
JSON representation
My leetcode solution repository
- Host: GitHub
- URL: https://github.com/beakerandjake/leetcode
- Owner: beakerandjake
- License: gpl-3.0
- Created: 2023-02-17T16:58:00.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-13T20:08:46.000Z (10 months ago)
- Last Synced: 2024-04-13T21:51:24.487Z (10 months ago)
- Topics: leetcode, leetcode-javascript, leetcode-solutions
- Language: JavaScript
- Homepage:
- Size: 1.34 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# leetcode
Contains my leetcode solutions.
I don't like coding in a browser so I added tools to support local development:
- Generate a solution file for the problem, with the problem description and blank code snippet.
- Generate the test file and test cases for the problem.
- Minify a problems source code and copy to clipboard so it can be submitted easily.
- Reset the source of a previously solved problem so it can be practiced.# Usage
Clone the repository and install the packages:
```sh
git clone https://github.com/beakerandjake/leetcode
cd leetcode
npm install
```## Commands
### `test [problem-number]`
Run the tests for all problems:
```sh
npm run test
```Run the test for a specific problem
```sh
npm run test 42
```### `touch [problem-slug|url] [--reset]`
Create the source and test file for the specified problem, commits these files to git, and finally opens them in vs code.
The source file is added to `src/` and test file is added to `tests/`.
An attempt is made to scrape the inputs and expected outputs from each example in the problem description. If scraping is successful a test case will be generated for each example and will provide the function with the correct inputs and test the result against the expected output. This process is not always successful so be sure to double check the generated test.
To touch the daily question, invoke with no arguments:
```sh
npm run touch
```
If touch is invoked with an argument, it should be either the problem slug or the full problem url.The problem slug is located in the problems url `leetcode.com/problems/SLUG/...`
To touch problem #1 (https://leetcode.com/problems/two-sum) using the problem slug:
```sh
npm run touch two-sum
```
To touch problem #1 (https://leetcode.com/problems/two-sum) using the full url:
```sh
npm run touch https://leetcode.com/problems/two-sum
```Additionally you can use the `--reset` flag to clear the existing source code for the problem. This is helpful if you want to practice the implementation.
```sh
npm run touch two-sum -- --reset
```Note the `--` is necessary to tell npm that the `--reset` flag is not for npm but for the `touch` command.
### `uglify `
Uglifies the problem source code outputs it to the console and attempts to copy it to the clipboard (if `xclip` is installed on the system).
You can paste this output into the leetcode editor and submit your solution.
To uglify problem 42:
```sh
npm run uglify 42
```Any additional arguments you pass to this command will be forwarded to uglify.js.
For example to tell uglify-js to not mangle quoted property names:
```sh
npm run uglify 42 -- --mangle-props keep_quoted
```### `info [problem-slug|url] [--reset]`
Returns information about the specified problem, including the difficulty and number of likes/dislikes. Can optionally include the tags of the problem.
If provided no arguments, will return information about the problem of the day.
To get the info about a specific problem use the problem slug or url:
```sh
npm run info two-sum
```
```sh
npm run info https://leetcode.com/problems/two-sum
```To include the tags in the output, use the `--tags` option:
```sh
run info https://leetcode.com/problems/two-sum -- --tags
```### `count`
Returns the total number of problems that are in the src/ folder.
```sh
npm run count
```### `today`
Returns the total number of problems that were created today.
```sh
npm run today
```### `ctci`
Returns the number of problems solved out of the book [Cracking the Coding Interview](https://www.crackingthecodinginterview.com/)
Note this isn't a perfect mapping, and a lot of problems in the book don't map to a leetcode problem, additionally I may have missed some problems while mapping.
```sh
npm run ctci
```Additionally you can pass the `--remaining` flag to list the remaining problems:
```sh
npm run ctci -- --remaining
```## Authentication
If you have leetcode premium and wish to use the `touch` command with premium problems, you will need to authenticate.
Create an `.env` file at the root of the repository. Add an environment variable named `LEETCODE_SESSION_TOKEN` with the value set to your leetcode session cookie.
```sh
echo 'LEETCODE_SESSION_TOKEN=YOURTOKENHERE' > .env
```This file *should not* be committed to source control. It is ignored by default in the `.gitignore`
# Acknowledgements
Big thanks to the [leetcode-query](https://github.com/JacobLinCool/LeetCode-Query) package, it removed a lot of the copy and paste tedium when creating the source files for problems.