Personal notes for leetcode.com solutions with support for local building and unit testing.
Top interviewed: 76 / 145
In total: 109 / 1411
Solutions that are 99.00%+ in running time: 66
- Linked list: 16ms (top 100.00%)
- Hash table (map): 8ms (top 100.00%)
- Use
INT_MAX
: 4ms (top 100.00%)
- Use
INT_MAX
: 8ms (top 99.90%)
- Lookup table: 52ms (top 100.00%)
- Dynamic programming: 4ms (top 100.00%)
- Two pointers: 12ms (top 100.00%)
- 4ms (top 100.00%)
- Two pointers: 112ms (top 99.88%)
- Two pointers: 8ms (top 100.00%)
- Deque: 4ms (top 100.00%)
- One pass: 8ms (top 100.00%)
- Stack: 4ms (top 100.00%)
- Two swaps: 12ms (top 100.00%)
- Deque: 8ms (top 100.00%)
- 0ms (top 100.00%)
- 20ms (top 95.79%)
- 20ms (top 99.75%)
- 0ms (top 100.00%)
- All
int
without<limits.h>
: 8ms (top 100.00%)
- 40ms (top 88.85%)
- 4ms (top 96.34%)
- 4ms (top 96.65%)
- 0ms (top 100.00%)
- 8ms (top 98.52%)
- 4ms (top 98.31%)
- 8ms (top 99.96%)
- 4ms (top 95.52%)
- 4ms (top 97.84%)
- 8ms (top 95.15%)
- 4ms (top 98.92%)
- 4ms (top 96.34%)
- 4ms (top 99.71%)
- 4ms (top 99.84%)
- 8ms (top 95.32%)
- 8ms (top 96.44%)
- 40ms (top 95.50%)
- 4ms (top 96.07%)
- 4ms (top 99.62%)
- 0ms (top 100.00%)
- 4ms (top 99.99%)
- 8ms (top 100.00%)
- 0ms (top 100.00%)
- 4ms (top 93.30%)
- 0ms (top 100.00%)
- 4ms (top 99.39%)
- 0ms (top 100.00%)
- 0ms (top 100.00%)
- 4ms (top 90.67%)
- 44ms (top 98.55%)
- 4ms (top 99.56%)
- 0ms (top 100.00%)
- sliding window: 32ms (top 38.25%)
- optimized sliding window: 44ms (top 19.33%)
- hash: 4ms (top 99.92%)
- 4ms (top 90.46%)
- 4ms (top 99.99%)
- 0ms (top 100.00%)
- 4ms (top 89.75%)
- 12ms (top 61.51%)
- 24ms (top 80.31%)
- 4ms (top 99.83%)
- 16ms (top 95.40%)
- 0ms (top 100.00%)
- 0ms (top 100.00%)
- 0ms (top 100.00%)
- 16ms (top 99.85%)
- 4ms (top 99.16%)
- 32ms (top 94.91%)
- 28ms (top 89.32%)
- 0ms (top 100.00%)
- 4ms (top 99.88%)
- 12ms (top 91.72%)
- 0ms (top 100.00%)
- 0ms (top 100.00%)
- 0ms (top 100.00%)
- 4ms (top 99.81%)
- 8ms (top 99.64%)
- 84ms (top 72.87%)
- 0ms (top 100.00%)
- 0ms (top 100.00%)
- 12ms (top 68.31%)
- 4ms (top 99.54%)
Category | Problems |
---|---|
Sort/search | 026, 031, 036, 041, 048, 054, 055, 056, 073, 074, 075, 118, 121, 122, 123, 128, 134, 136, 153, 215, 240, 278 |
String | 005, 006, 008, 010, 014, 028, 038, 043, 044, 127 |
Numerical | 007, 009, 029, 050, 066, 069, 279 |
Hash/Lookup | 001, 003, 012, 013, 020, 030, 049, 076, 187, 349, 350 |
Stack/Queue/Deque | 023, 032, 094, 102, 103, 116, 150 |
Linked list | 002, 019, 021, 024 |
Two pointers | 011, 015, 016, 018, 027, 042, 084, 088, 125, 287 |
Recursion | 004, 025, 033, 034, 035, 045, 079, 098, 101, 104, 105, 108, 111, 124, 130, 301 |
Backtracking | 017, 022, 037, 039, 040, 046, 047, 051, 060, 078 |
DP | 053, 062, 063, 064, 070, 091, 120, 131, 198, 213, 221, 300 |
Note that binary tree problems are mostly included in the
Recursion
category.
《Ubuntu计算机视觉开发环境配置(Python/C++)》 《Manjaro计算机视觉开发环境配置(Python/C++)》 《Windows配置VSCode+CMake+Ninja+Boost.Test的C++开发环境》
- Ubuntu 18.04 / Manjaro 19.0 / Windows 10 / macOS Catalina 10.15.3
- Visual Studio Code with following extensions:
- C/C++ (ms-vscode.cpptools)
- C/C++ Clang Command Adapter (mitaki28.vscode-clang) (optional)
- CMake (twxs.cmake)
- CMake Tools (vector-of-bool.cmake-tools)
- CodeLLDB (vadimcn.vscode-lldb) (optional)
sudo snap install --classic code
sudo apt-get install pylint
- clang (used by default. You can use other tools as long as your
.vscode/c_cpp_properties.json
file is modified correctly)
wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo apt-get update
sudo apt-get install clang-8 lldb-8
- CMake
- Boost (for unit testing)
wget -O boost_1_70_0.tar.gz https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz
tar xzvf boost_1_70_0.tar.gz
cd boost_1_70_0/
sudo apt-get update
sudo apt-get install build-essential g++ python-dev autotools-dev libicu-dev build-essential libbz2-dev libboost-all-dev
./bootstrap.sh --prefix=/usr/
./b2
sudo ./b2 install
Each folder contains 3 files: solution.hpp
, solution.cpp
and solution_test.cpp
. The first folder 001-Two-Sum
contains an additional main.cpp
file, in case you don't feel like using unit testing and you can test your own cases in main.cpp
.
Add following lines to your settings.json
to configure the building and linting:
{
"clang.executable": "clang++",
"clang.cflags": ["c11"],
"clang.cxxflags": ["-std=c++17"],
"lldb.executable": "lldb"
}
Steps to build a solution:
-
Change the line
set(PROBLEM_NAME {Problem_Folder})
inCMakeLists.txt
to choose the problem you want to solve, in which{Problem_Folder}
is the folder name of the problem. For example,set(PROBLEM_NAME "001-Two-Sum")
. -
Press
Ctrl
+Shift
+P
to bring up the Command Palette of VSCode. Type inCMake
, and look for aCMake: Configure
command, select it. It will configure the cache files and makefile which are located inbuild
folder by default. -
Type in or look for a
CMake: Build
command in the Command Palette and execute it. It will compile the source codes of the solution that you previously chose. -
Debug Press
Ctrl
+Shift
+D
or click the bug icon on the left. The.vscode/launch.json
for debugging is already set up for you, and both GDB and LLDB is supported.gdb: Choose
(gdb) Launch
and you're good to go.lldb: Choose
(lldb) Launch
. You may need to disable and re-enablems-vscode.cpptools
andmitaki28.vscode-clang
extensions in case the variables won't properly display in "Watch" Panel. Data visualization is supported (https://github.com/vadimcn/vscode-lldb/wiki/Data-visualization). -
Unit testing Type in or look for a
CMake: Run tests
command in the Command Palette and execute it. It will run all test cases insolution_test.cpp
. Feel free to add your own test cases.
Clear build folder:
- Press
Ctrl
+Shift
+P
to bring up the Command Palette. Type inTask: Run Task
and pressenter
. Chooseclean
will delete everything in thebuild
folder. Bear in mind that you need to configure the project after cleaning the folder or switching to another solution, by either executingTask: Run Task
->configure
orCMake: Configure
.